Class: SongPro::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/song_pro/song.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSong

Returns a new instance of Song.



18
19
20
21
# File 'lib/song_pro/song.rb', line 18

def initialize
  @sections = []
  @custom = {}
end

Instance Attribute Details

#albumObject

Returns the value of attribute album.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def album
  @album
end

#artistObject

Returns the value of attribute artist.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def artist
  @artist
end

#capoObject

Returns the value of attribute capo.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def capo
  @capo
end

#customObject

Returns the value of attribute custom.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def custom
  @custom
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def key
  @key
end

#sectionsObject

Returns the value of attribute sections.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def sections
  @sections
end

#tempoObject

Returns the value of attribute tempo.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def tempo
  @tempo
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def title
  @title
end

#tuningObject

Returns the value of attribute tuning.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def tuning
  @tuning
end

#yearObject

Returns the value of attribute year.



7
8
9
# File 'lib/song_pro/song.rb', line 7

def year
  @year
end

Instance Method Details

#chordsObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/song_pro/song.rb', line 27

def chords
  sections.collect do |section|
    section.lines.collect do |line|
      if line.measures?
        line.measures.collect(&:chords)
      else
        line.parts.collect(&:chord)
      end
    end
  end.flatten.uniq.reject(&:empty?)
end

#set_custom(key, value) ⇒ Object



23
24
25
# File 'lib/song_pro/song.rb', line 23

def set_custom(key, value)
  @custom[key.to_sym] = value
end

#to_htmlObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/song_pro/song.rb', line 39

def to_html
  mab = Markaby::Builder.new(song: self)
  mab.div.song do
    h1.title song.title if song.title
    h2.artist song.artist if song.artist

    dl.information do
      if song.tuning
        dt.tuning 'Tuning'
        dd.tuning song.tuning
      end
      if song.capo
        dt.capo 'Capo'
        dd.capo song.capo
      end
      if song.key
        dt.key 'Key'
        dd.key song.key
      end
      if song.tempo
        dt.tempo 'Tempo'
        dd.tempo song.tempo
      end
      if song.year
        dt.year 'Year'
        dd.year song.year
      end
      if song.album
        dt.album 'Album'
        dd.album song.album
      end
    end

    song.sections.each do |section|
      div.section do
        div.name section.name
        div.lines do
          section.lines.each do |line|
            if line.tablature?
              div.tablature do
                line.tablature
              end
            elsif line.measures?
              div.measures do
                line.measures.each do |measure|
                  div.measure do
                    measure.chords.each do |chord|
                      div.chord chord
                    end
                  end
                end
              end
            else
              div.line do
                line.parts.each do |part|
                  div.part do
                    div.chord part.chord
                    div.lyric part.lyric
                  end
                end
              end
            end
          end
        end
      end
    end
  end

  mab.to_s
end