Module: TagParser::ClassMethods

Defined in:
lib/cooklang_rb/tag_parser.rb

Instance Method Summary collapse

Instance Method Details

#multi_word_patternObject



30
31
32
# File 'lib/cooklang_rb/tag_parser.rb', line 30

def multi_word_pattern
  /#{tag}#{MULTI_NAME}{#{QUANTITY}}/
end

#parse_from(buffer) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cooklang_rb/tag_parser.rb', line 22

def parse_from(buffer)
  if buffer.match? multi_word_pattern
    new(**multi_word_pattern.match(buffer.scan(multi_word_pattern)).named_captures.transform_keys(&:to_sym))
  else
    new(name: buffer.scan(single_word_pattern))
  end
end

#single_word_patternObject



34
35
36
# File 'lib/cooklang_rb/tag_parser.rb', line 34

def single_word_pattern
  /#{tag}#{NAME}/
end