Class: Farseer::Or
Instance Method Summary collapse
-
#initialize(*parsers) ⇒ Or
constructor
A new instance of Or.
- #parse(input) ⇒ Object
- #parse_helper(input) ⇒ Object
Methods included from MapFactory
Constructor Details
#initialize(*parsers) ⇒ Or
Returns a new instance of Or.
7 8 9 10 |
# File 'lib/farseer/or.rb', line 7 def initialize(*parsers) @parsers = parsers.flatten freeze end |
Instance Method Details
#parse(input) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/farseer/or.rb', line 12 def parse(input) case @parsers.length when 0 then Maybe.none when 1 then @parsers.first.parse(input) else parse_helper(input) end end |
#parse_helper(input) ⇒ Object
20 21 22 23 24 |
# File 'lib/farseer/or.rb', line 20 def parse_helper(input) @parsers.reduce do |acc, parser| acc.parse(input).bind_none { parser.parse(input) } end end |