class FoodIngredientParser::Loose::Parser

Public Class Methods

new() click to toggle source

Create a new food ingredient stream parser @return [FoodIngredientParser::StreamParser]

# File lib/food_ingredient_parser/loose/parser.rb, line 12
def initialize
end

Public Instance Methods

parse(s, clean: true, normalize: true, **options) click to toggle source

Parse food ingredient list text into a structured representation.

@option clean [Boolean] pass false to disable correcting frequently occuring issues @option normalize [Boolean] pass false to disable some normalizations (handling missing names) @return [FoodIngredientParser::Loose::Node] structured representation of food ingredients

# 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