Class: IMW::Parsers::Flat

Inherits:
Object
  • Object
show all
Defined in:
lib/imw/parsers/flat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Flat

Returns a new instance of Flat.



11
12
13
14
15
16
# File 'lib/imw/parsers/flat.rb', line 11

def initialize io
  self.io          = io
  self.state       = nil
  self.accumulated = []
  self.current     = nil
end

Instance Attribute Details

#accumulatedObject

Returns the value of attribute accumulated.



8
9
10
# File 'lib/imw/parsers/flat.rb', line 8

def accumulated
  @accumulated
end

#currentObject

Returns the value of attribute current.



9
10
11
# File 'lib/imw/parsers/flat.rb', line 9

def current
  @current
end

#ioObject

Returns the value of attribute io.



6
7
8
# File 'lib/imw/parsers/flat.rb', line 6

def io
  @io
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/imw/parsers/flat.rb', line 7

def state
  @state
end

Instance Method Details

#accumulate!Object



29
30
31
# File 'lib/imw/parsers/flat.rb', line 29

def accumulate!
  self.accumulated << current
end

#complete?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/imw/parsers/flat.rb', line 33

def complete?
  io.eof?
end

#parse!Object



22
23
24
25
26
27
# File 'lib/imw/parsers/flat.rb', line 22

def parse!
  while (! complete?)
    read_next!
    react_to_input!
  end
end

#react_to_input!Object



37
38
39
# File 'lib/imw/parsers/flat.rb', line 37

def react_to_input!
  raise IMW::NotImplementedError.new("Override the `react_to_input!' method of the #{self.class} class")
end

#read_next!Object



18
19
20
# File 'lib/imw/parsers/flat.rb', line 18

def read_next!
  self.current = io.readline.chomp
end