Class: RubyGrep::Line
- Inherits:
-
Object
- Object
- RubyGrep::Line
- Defined in:
- lib/ruby-grep/line.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #aligned_line_number ⇒ Object
- #colorized_line(expression) ⇒ Object
-
#initialize(contents, number, file) ⇒ Line
constructor
A new instance of Line.
Constructor Details
#initialize(contents, number, file) ⇒ Line
Returns a new instance of Line.
7 8 9 10 11 12 |
# File 'lib/ruby-grep/line.rb', line 7 def initialize(contents, number, file) @contents = contents @number = number + 1 @file = file @file_name = @file.file_name end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
5 6 7 |
# File 'lib/ruby-grep/line.rb', line 5 def contents @contents end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/ruby-grep/line.rb', line 5 def file @file end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/ruby-grep/line.rb', line 5 def number @number end |
Instance Method Details
#aligned_line_number ⇒ Object
18 19 20 21 |
# File 'lib/ruby-grep/line.rb', line 18 def aligned_line_number shift = @file.max_line_number_length sprintf("%#{shift}d", @number) end |
#colorized_line(expression) ⇒ Object
14 15 16 |
# File 'lib/ruby-grep/line.rb', line 14 def colorized_line(expression) "\s\s\s\s#{colorize_line_number(aligned_line_number)}: #{colorize_text(expression).lstrip}" end |