Class: LineStateMachine
- Inherits:
-
Object
- Object
- LineStateMachine
- Defined in:
- lib/data/line_state_machine.rb
Overview
First pass at state machine for converting sequence of formatted lines into a different
set of word values, in this case "<N>, blank, |, blank, <footer title>" get converted
into [ "END_OF_PAGE", "<page number>", "<title as a single word>"]
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#pages ⇒ Object
Returns the value of attribute pages.
Instance Method Summary collapse
-
#initialize ⇒ LineStateMachine
constructor
A new instance of LineStateMachine.
- #process(line, wordIndex) ⇒ Object
- #resetState(data) ⇒ Object
Constructor Details
#initialize ⇒ LineStateMachine
Returns a new instance of LineStateMachine.
11 12 13 14 15 16 |
# File 'lib/data/line_state_machine.rb', line 11 def initialize @bucket = "Page 0" @pages = {} @dataQueue = [] super end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/data/line_state_machine.rb', line 9 def bucket @bucket end |
#pages ⇒ Object
Returns the value of attribute pages.
9 10 11 |
# File 'lib/data/line_state_machine.rb', line 9 def pages @pages end |
Instance Method Details
#process(line, wordIndex) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/data/line_state_machine.rb', line 27 def process(line, wordIndex) data = line.split # we are looking for a blank, a pipe, or a page number if (data.length == 0) then if (self.foundBlank) then return [] end end if (data.length == 1) then if (data[0] == "|") then if (self.foundPipe) then return [] end end ival = data[0].to_i if (ival > 0) then if (self.foundN) then @potentialPageNumber = ival @dataQueue << data # in case this really isn't it return [] end end end # if we are looking for the title, the entire line is the title if (data.length > 0) then if (self.foundTitle) then @dataQueue = [] @bucket = "Page #{@potentialPageNumber}" @pages[@bucket] = wordIndex return [] end end resetState(data) end |
#resetState(data) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/data/line_state_machine.rb', line 18 def resetState(data) self.reset result = [] result << @dataQueue result << data @dataQueue = [] return result.flatten end |