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

- (Parser) initialize(music_string)

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

- (Object) parsed_elements (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

- (Object) parser (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

+ (Object) elementize(str)



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

+ (Object) parse_element!(element, klass)



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

- (Object) error_on



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

def error_on
  @last_error_on
end

- (Object) to_stretto(pattern = nil)



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

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

- (Boolean) valid?

Returns:

  • (Boolean)


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

def valid?
  not parsed_string.nil?
end