Class: InevitableCacophony::Parser::Rhythms

Inherits:
Object
  • Object
show all
Defined in:
lib/inevitable_cacophony/parser/rhythms.rb

Constant Summary collapse

SIMPLE_RHYTHM_SENTENCE =

Regular expressions used in parsing

/The (?<name>[[:alpha:]]+) rhythm is a single line with [-a-z ]+ beats?( divided into [-a-z ]+ bars in a [-0-9]+ pattern)?(\.|$)/
COMPOSITE_RHYTHM_SENTENCE =
/The (?<name>[[:alpha:]]+) rhythm is made from [-a-z ]+ patterns: (?<patterns>[^.]+)(\.|$)/
THE_RHYTHM =

“the <rhythm>”. Used to match individual components in COMPOSITE_RHYTHM_SENTENCE

/the (?<rhythm_name>[[:alpha:]]+)( \((?<reference_comment>[^)]+)\))?/
IS_PRIMARY_COMMENT =
'considered the primary'
COMBINATION_TYPE_SENTENCE =

Used to recognise how multiple rhythms are to be combined

/The patterns are to be played (?<type_summary>[^.,]+), [^.]+\./
POLYRHYTHM_TYPE_SUMMARY =
'over the same period of time'

Instance Method Summary collapse

Instance Method Details

#parse(form_text) ⇒ Hash{Symbol,Rhythm}

Parses the rhythms from the given form text.

Parameters:

  • form_text (String)

Returns:



50
51
52
53
54
55
56
57
# File 'lib/inevitable_cacophony/parser/rhythms.rb', line 50

def parse(form_text)
	parser = Parser::SectionedText.new(form_text)
        
	simple_rhythms = parse_simple_rhythms(parser)
	composite_rhythms = parse_composite_rhythms(parser, simple_rhythms)
        
	simple_rhythms.merge(composite_rhythms)
end