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



190
191
192
193
# File 'lib/grepper.rb', line 190

def initialize(line)
  @before = @after = nil
  @line = line
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



189
190
191
# File 'lib/grepper.rb', line 189

def after
  @after
end

#beforeObject

Returns the value of attribute before.



189
190
191
# File 'lib/grepper.rb', line 189

def before
  @before
end

#lineObject

Returns the value of attribute line.



189
190
191
# File 'lib/grepper.rb', line 189

def line
  @line
end

#linenoObject

Returns the value of attribute lineno.



189
190
191
# File 'lib/grepper.rb', line 189

def lineno
  @lineno
end

Instance Method Details

#absolute_endObject



205
206
207
# File 'lib/grepper.rb', line 205

def absolute_end
  lineno + after.to_s.scan(/\n/).size
end

#absolute_startObject



201
202
203
# File 'lib/grepper.rb', line 201

def absolute_start
  lineno - before.to_s.scan(/\n/).size
end

#total_line_countObject



195
196
197
198
199
# File 'lib/grepper.rb', line 195

def total_line_count
  before.to_s.scan(/\n/).size +
  after.to_s.scan(/\n/).size +
  1
end