Class: TextExtractor::Extraction

Inherits:
Object
  • Object
show all
Defined in:
lib/text_extractor/extraction.rb

Overview

represents a single execution of a TextExtractor

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#extractorObject (readonly)

Returns the value of attribute extractor.



4
5
6
# File 'lib/text_extractor/extraction.rb', line 4

def extractor
  @extractor
end

#inputObject (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/text_extractor/extraction.rb', line 4

def input
  @input
end

#matchesObject (readonly)

Returns the value of attribute matches.



4
5
6
# File 'lib/text_extractor/extraction.rb', line 4

def matches
  @matches
end

#posObject (readonly)

Returns the value of attribute pos.



4
5
6
# File 'lib/text_extractor/extraction.rb', line 4

def pos
  @pos
end

#reObject (readonly)

Returns the value of attribute re.



4
5
6
# File 'lib/text_extractor/extraction.rb', line 4

def re
  @re
end

#valuesObject (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_matchesObject



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

#scanObject



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