class FoodIngredientParser::Strict::Grammar::IngredientNode

Ingredient

Public Instance Methods

to_h() click to toggle source
# File lib/food_ingredient_parser/strict/nodes.rb, line 43
def to_h
  h = {}
  h.merge!(to_a_deep(ing, IngredientNode)&.first&.to_h || {}) if respond_to?(:ing)
  h.merge!(to_a_deep(amount, AmountNode)&.first&.to_h || {}) if respond_to?(:amount)
  h[:name] = name.text_value if respond_to?(:name)
  h[:name] = pre.text_value + h[:name] if respond_to?(:pre)
  h[:name] = h[:name] + post.text_value if respond_to?(:post)
  h[:marks] = [mark.text_value] if respond_to?(:mark) && mark.text_value != ''
  h
end