Class: FoodIngredientParser::Loose::Parser

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

Instance Method Summary collapse

Constructor Details

#initializeFoodIngredientParser::StreamParser

Create a new food ingredient stream parser



12
13
# File 'lib/food_ingredient_parser/loose/parser.rb', line 12

def initialize
end

Instance Method Details

#parse(s, clean: true, normalize: true, **options) ⇒ FoodIngredientParser::Loose::Node

Parse food ingredient list text into a structured representation.

Parameters:

  • clean (Hash) (defaults to: true)

    a customizable set of options

  • normalize (Hash) (defaults to: true)

    a customizable set of options

Options Hash (clean:):

  • pass (Boolean)

    false to disable correcting frequently occuring issues

Options Hash (normalize:):

  • pass (Boolean)

    false to disable some normalizations (handling missing names)

Returns:



20
21
22
23
24
25
26
27
# File 'lib/food_ingredient_parser/loose/parser.rb', line 20

def parse(s, clean: true, normalize: true, **options)
  s = FoodIngredientParser::Cleaner.clean(s) if clean
  n = Scanner.new(s).scan
  n = Transform::Amount.transform!(n) if n
  n = Transform::SplitENumbers.transform!(n) if n
  n = Transform::HandleMissingName.transform!(n) if n && normalize
  n
end