Class: Stretto::Parser

Inherits:
Object show all
Defined in:
lib/stretto/parsers/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(music_string) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
# File 'lib/stretto/parsers/parser.rb', line 10

def initialize(music_string)
  @music_string = music_string
  @parser       = StrettoGrammarParser.new
end

Instance Attribute Details

#parsed_elementsObject (readonly)

Returns the value of attribute parsed_elements.



8
9
10
# File 'lib/stretto/parsers/parser.rb', line 8

def parsed_elements
  @parsed_elements
end

#parserObject (readonly)

Returns the value of attribute parser.



8
9
10
# File 'lib/stretto/parsers/parser.rb', line 8

def parser
  @parser
end

Class Method Details

.elementize(str) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/stretto/parsers/parser.rb', line 78

def elementize(str)
  str.to_s.split('::').last.
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

.parse_element!(element, klass) ⇒ Object



74
75
76
# File 'lib/stretto/parsers/parser.rb', line 74

def parse_element!(element, klass)
  send(:"parse_#{elementize(klass)}!", element)
end

Instance Method Details

#error_onObject



23
24
25
# File 'lib/stretto/parsers/parser.rb', line 23

def error_on
  @last_error_on
end

#to_stretto(pattern = nil) ⇒ Object



15
16
17
# File 'lib/stretto/parsers/parser.rb', line 15

def to_stretto(pattern = nil)
  parsed_string.to_stretto(pattern)
end

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/stretto/parsers/parser.rb', line 19

def valid?
  not parsed_string.nil?
end