Class: FoodIngredientParser::Strict::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFoodIngredientParser::Parser

Create a new food ingredient parser



14
15
16
# File 'lib/food_ingredient_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_ingredient_parser/strict/parser.rb', line 10

def parser
  @parser
end

Instance Method Details

#parse(s, clean: true, **options) ⇒ FoodIngredientParser::Grammar::RootNode

Note:

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

Parse food ingredient list text into a structured representation.

Parameters:

  • clean (Hash) (defaults to: true)

    a customizable set of options

Options Hash (clean:):

  • pass (Boolean)

    false to disable correcting frequently occuring issues

Returns:

  • (FoodIngredientParser::Grammar::RootNode)

    structured representation of food ingredients



23
24
25
26
# File 'lib/food_ingredient_parser/strict/parser.rb', line 23

def parse(s, clean: true, **options)
  s = FoodIngredientParser::Cleaner.clean(s) if clean
  @parser.parse(s, **options)
end