Class: FoodIngredientParser::Loose::Transform::HandleMissingName
- Inherits:
-
Object
- Object
- FoodIngredientParser::Loose::Transform::HandleMissingName
- Defined in:
- lib/food_ingredient_parser/loose/transform/handle_missing_name.rb
Overview
Transforms node tree to handle missing names.
The loose parser can return a node tree that has some ingredients without a name. Usually this means that either the parser wasn't smart enough to understand the input, or the input was not strictly clear (e.g. a case like "herbs, (oregano), salt" is often seen).
When a contained node is found which doesn't have a name:
- For the amount (if any): ignore it (as it's often ambiguous which ingredient it belongs to)
- For the marks (if any)
- if the node has no siblings and no containing ingredients, add the mark to the parent (if any)
- else ignore it (we might instead add it to the containing ingredients)
- For the containing ingredients (if any):
- if the previous ingredient is present and doesn't contain ingredients already, assume the current contained ingredients are actually part of the previous ingredient.
- if there is no previous ingredient, assume the nesting is wrong and insert them before the other ingredients one depth level above.
- if there is a previous ingredient which contains ingredients, we can't make much of it, to avoid losing them, add them as contained ingredients to the previous ingredient.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(node) ⇒ HandleMissingName
constructor
A new instance of HandleMissingName.
- #transform! ⇒ Object
Constructor Details
#initialize(node) ⇒ HandleMissingName
Returns a new instance of HandleMissingName.
27 28 29 |
# File 'lib/food_ingredient_parser/loose/transform/handle_missing_name.rb', line 27 def initialize(node) @node = node end |
Class Method Details
.transform!(node) ⇒ Object
23 24 25 |
# File 'lib/food_ingredient_parser/loose/transform/handle_missing_name.rb', line 23 def self.transform!(node) new(node).transform! end |
Instance Method Details
#transform! ⇒ Object
31 32 33 34 |
# File 'lib/food_ingredient_parser/loose/transform/handle_missing_name.rb', line 31 def transform! transform_children!(@node) @node end |