Class: Regex::Extractor::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/regex/extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, match) ⇒ Match

match - Instance of MatchData



452
453
454
455
# File 'lib/regex/extractor.rb', line 452

def initialize(input, match)
  @input = input
  @match = match
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



447
448
449
# File 'lib/regex/extractor.rb', line 447

def input
  @input
end

#matchObject (readonly)

Returns the value of attribute match.



448
449
450
# File 'lib/regex/extractor.rb', line 448

def match
  @match
end

Instance Method Details

#[](i) ⇒ Object



458
459
460
# File 'lib/regex/extractor.rb', line 458

def [](i)
  @match[i]
end

#breakdownObject



468
469
470
471
472
473
474
475
476
477
478
# File 'lib/regex/extractor.rb', line 468

def breakdown
  m = []
  range = (0...match.size)
  range.each do |i|
    char = match.offset(i)[0]
    line = line_at(char)
    part = match[i]
    m << {'index'=>i, 'line'=>line, 'char'=>char, 'text'=>part}
  end
  m
end

#info(index) ⇒ Object



481
482
483
484
485
486
# File 'lib/regex/extractor.rb', line 481

def info(index)
  text = match[index]
  char = match.offset(index)[0]
  line = line_at(char)
  return text, char, line
end

#line_at(char) ⇒ Object

Return the line number of the char position within text.



489
490
491
492
# File 'lib/regex/extractor.rb', line 489

def line_at(char)
  return nil unless char
  text[0..char].count("\n") + 1
end

#sizeObject



463
464
465
# File 'lib/regex/extractor.rb', line 463

def size
  @match.size
end

#textObject



495
496
497
# File 'lib/regex/extractor.rb', line 495

def text
  Extractor.input_cache(input)
end