Class: TextExtractor::Extraction
- Inherits:
-
Object
- Object
- TextExtractor::Extraction
- Defined in:
- lib/text_extractor/extraction.rb
Overview
represents a single execution of a TextExtractor
Instance Attribute Summary collapse
-
#extractor ⇒ Object
readonly
Returns the value of attribute extractor.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#re ⇒ Object
readonly
Returns the value of attribute re.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #extraction_match(match) ⇒ Object
- #extraction_matches ⇒ Object
-
#initialize(input, extractor, fill = {}) ⇒ Extraction
constructor
A new instance of Extraction.
- #scan ⇒ Object
Constructor Details
#initialize(input, extractor, fill = {}) ⇒ Extraction
Returns a new instance of Extraction.
6 7 8 9 10 11 12 13 |
# File 'lib/text_extractor/extraction.rb', line 6 def initialize(input, extractor, fill = {}) @input = input @extractor = extractor @fill = fill @pos = 0 @matches = [] @last_match = nil end |
Instance Attribute Details
#extractor ⇒ Object (readonly)
Returns the value of attribute extractor.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def extractor @extractor end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def input @input end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def matches @matches end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def pos @pos end |
#re ⇒ Object (readonly)
Returns the value of attribute re.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def re @re end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
4 5 6 |
# File 'lib/text_extractor/extraction.rb', line 4 def values @values end |
Instance Method Details
#extraction_match(match) ⇒ Object
21 22 23 |
# File 'lib/text_extractor/extraction.rb', line 21 def extraction_match(match) extractor.find_record_for(match).extraction(match, @fill) end |
#extraction_matches ⇒ Object
15 16 17 18 19 |
# File 'lib/text_extractor/extraction.rb', line 15 def extraction_matches matches.flat_map do |match| extraction_match(match) end end |
#scan ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/text_extractor/extraction.rb', line 25 def scan re = extractor.to_re loop do match = input.match(re, pos) break unless match @pos = match.end(0) @matches << match end self end |