Class: FoodFishParser::Strict::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/food_fish_parser/strict/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFoodFishParser::Strict::Parser

Create a new fish detail parser



14
15
16
# File 'lib/food_fish_parser/strict/parser.rb', line 14

def initialize
  @parser = Grammar::RootParser.new
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



10
11
12
# File 'lib/food_fish_parser/strict/parser.rb', line 10

def parser
  @parser
end

Instance Method Details

#parse(s, anywhere: false, **options) ⇒ FoodFishParser::Strict::Grammar::RootNode

Note:

Unrecognized options are passed to Treetop, but this is not guarenteed to remain so forever.

Parse food fish text into a structured representation.

Parameters:

  • s (String)

    text to parse

  • anywhere (Bool) (defaults to: false)

    false assume the text is only fish details, true to search for fish details in the text

Returns:



24
25
26
27
28
29
30
# File 'lib/food_fish_parser/strict/parser.rb', line 24

def parse(s, anywhere: false, **options)
  if anywhere
    options = options.merge(root: :root_anywhere, consume_all_input: false)
  end

  @parser.parse(s, **options)
end