Class: Cooklang::Parsers::IngredientParser
- Inherits:
-
Object
- Object
- Cooklang::Parsers::IngredientParser
- Defined in:
- lib/cooklang/parsers/ingredient_parser.rb
Instance Method Summary collapse
-
#initialize(stream) ⇒ IngredientParser
constructor
A new instance of IngredientParser.
- #parse ⇒ Object
Constructor Details
#initialize(stream) ⇒ IngredientParser
Returns a new instance of IngredientParser.
6 7 8 |
# File 'lib/cooklang/parsers/ingredient_parser.rb', line 6 def initialize(stream) @stream = stream end |
Instance Method Details
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cooklang/parsers/ingredient_parser.rb', line 10 def parse return nil unless @stream.current&.type == :ingredient_marker @stream.consume(:ingredient_marker) # Skip the @ marker return nil if invalid_syntax? brace_index = find_next_brace if brace_index parse_braced_ingredient(brace_index) else parse_simple_ingredient end end |