Class: IRealB::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/irealb/parser.rb,
lib/irealb/parser/tune.rb,
lib/irealb/parser/chord.rb,
lib/irealb/parser/runner.rb,
lib/irealb/parser/version.rb,
lib/irealb/parser/chord_grouping.rb

Defined Under Namespace

Classes: Chord, ChordGrouping, Runner, Tune

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



14
15
16
17
# File 'lib/irealb/parser.rb', line 14

def initialize(text)
  @text = text
  @tunes = []
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/irealb/parser.rb', line 11

def text
  @text
end

#tunesObject (readonly)

Returns the value of attribute tunes.



12
13
14
# File 'lib/irealb/parser.rb', line 12

def tunes
  @tunes
end

Instance Method Details

#as_json(options = {}) ⇒ Object



28
29
30
# File 'lib/irealb/parser.rb', line 28

def as_json(options = {})
  tunes.map(&:as_json)
end

#parseObject



19
20
21
22
23
24
25
26
# File 'lib/irealb/parser.rb', line 19

def parse
  @text.split("=").in_groups_of(6).each do |raw_tune|
    parse_tune(raw_tune).tap do |tune|
      @tunes << tune if tune
    end
  end
  self
end