Class: Grepper::Match

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#afterObject

Returns the value of attribute after.



215
216
217
# File 'lib/grepper.rb', line 215

def after
  @after
end

#beforeObject

Returns the value of attribute before.



215
216
217
# File 'lib/grepper.rb', line 215

def before
  @before
end

#lineObject

Returns the value of attribute line.



215
216
217
# File 'lib/grepper.rb', line 215

def line
  @line
end

#linenoObject

Returns the value of attribute lineno.



215
216
217
# File 'lib/grepper.rb', line 215

def lineno
  @lineno
end

Instance Method Details

#absolute_endObject



231
232
233
# File 'lib/grepper.rb', line 231

def absolute_end
  lineno + (after || []).size
end

#absolute_startObject



227
228
229
# File 'lib/grepper.rb', line 227

def absolute_start
  lineno - (before || []).size
end

#total_line_countObject



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