Class: Grepper::Match
- Inherits:
-
Object
- Object
- Grepper::Match
- Defined in:
- lib/grepper.rb
Overview
Grepper::Match represents a match on a single line, possibly with before- and/or after-context.
Match instances are created automatically by the Grepper object when you run it.
Instance Attribute Summary collapse
-
#after ⇒ Object
Returns the value of attribute after.
-
#before ⇒ Object
Returns the value of attribute before.
-
#line ⇒ Object
Returns the value of attribute line.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
Instance Method Summary collapse
- #absolute_end ⇒ Object
- #absolute_start ⇒ Object
-
#initialize(line) ⇒ Match
constructor
A new instance of Match.
- #total_line_count ⇒ Object
Constructor Details
#initialize(line) ⇒ Match
Returns a new instance of Match.
216 217 218 219 |
# File 'lib/grepper.rb', line 216 def initialize(line) @before = @after = nil @line = line end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
215 216 217 |
# File 'lib/grepper.rb', line 215 def after @after end |
#before ⇒ Object
Returns the value of attribute before.
215 216 217 |
# File 'lib/grepper.rb', line 215 def before @before end |
#line ⇒ Object
Returns the value of attribute line.
215 216 217 |
# File 'lib/grepper.rb', line 215 def line @line end |
#lineno ⇒ Object
Returns the value of attribute lineno.
215 216 217 |
# File 'lib/grepper.rb', line 215 def lineno @lineno end |
Instance Method Details
#absolute_end ⇒ Object
231 232 233 |
# File 'lib/grepper.rb', line 231 def absolute_end lineno + (after || []).size end |
#absolute_start ⇒ Object
227 228 229 |
# File 'lib/grepper.rb', line 227 def absolute_start lineno - (before || []).size end |
#total_line_count ⇒ Object
221 222 223 224 225 |
# File 'lib/grepper.rb', line 221 def total_line_count before.to_s.scan(/\n/).size + after.to_s.scan(/\n/).size + 1 end |