Class: Regex::Extractor::Match
- Inherits:
-
Object
- Object
- Regex::Extractor::Match
- Defined in:
- lib/regex/extractor.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #breakdown ⇒ Object
- #info(index) ⇒ Object
-
#initialize(input, match) ⇒ Match
constructor
match - Instance of MatchData.
-
#line_at(char) ⇒ Object
Return the line number of the
char
position withintext
. - #size ⇒ Object
- #text ⇒ Object
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
#input ⇒ Object (readonly)
Returns the value of attribute input.
447 448 449 |
# File 'lib/regex/extractor.rb', line 447 def input @input end |
#match ⇒ Object (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 |
#breakdown ⇒ Object
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 |
#size ⇒ Object
463 464 465 |
# File 'lib/regex/extractor.rb', line 463 def size @match.size end |
#text ⇒ Object
495 496 497 |
# File 'lib/regex/extractor.rb', line 495 def text Extractor.input_cache(input) end |