Class: RubySearch::Formatter
- Inherits:
-
Struct
- Object
- Struct
- RubySearch::Formatter
- Defined in:
- lib/ruby_search/formatter.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file
4 5 6 |
# File 'lib/ruby_search/formatter.rb', line 4 def file @file end |
#matches ⇒ Object
Returns the value of attribute matches
4 5 6 |
# File 'lib/ruby_search/formatter.rb', line 4 def matches @matches end |
#options ⇒ Object
Returns the value of attribute options
4 5 6 |
# File 'lib/ruby_search/formatter.rb', line 4 def @options end |
Instance Method Details
#print ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_search/formatter.rb', line 21 def print if !matches.empty? || [:verbose] if block_given? yield to_str else puts to_str end end end |
#to_str ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_search/formatter.rb', line 5 def to_str string = '' string << "====#{file}\n".colorize(:cyan) matches.each do |match, i| string << i.to_s string << "\t" string << [ match.pre_match, match.to_s.colorize(:red), match.post_match ].join.chomp string << "\n" end string end |