Hi,
I'm trying to write a parser for cooking recipes.
It looks like this:
···
-----
require 'bspmess'
class Parser
STATES = [ :FIND_START, :SCAN_HEADER]
methods = { :FIND_START => self.find_start,
:SCAN_HEADER => self.scan_header
}
def initialize(msg)
@msg = msg
@state = :FIND_START
end
def run
@msg.each { |line|
scan line
}
end
def scan(line)
methods[@state].call(line)
end
def find_start(line)
puts "find_start "
@state = :SCAN_HEADER
end
def scan_header(line)
puts "scan header"
end
end
p = Parser.new(MSG)
p.run
-----
I get an error when the scan method is called first:
undefined method `find_start' for Parser:Class (NoMethodError)
Who can help me ?
Thanks in advance,
Uwe