Class: SongPro::Song
- Inherits:
-
Object
- Object
- SongPro::Song
- Defined in:
- lib/song_pro/song.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#capo ⇒ Object
Returns the value of attribute capo.
-
#custom ⇒ Object
Returns the value of attribute custom.
-
#key ⇒ Object
Returns the value of attribute key.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#tempo ⇒ Object
Returns the value of attribute tempo.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tuning ⇒ Object
Returns the value of attribute tuning.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #chords ⇒ Object
-
#initialize ⇒ Song
constructor
A new instance of Song.
- #set_custom(key, value) ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize ⇒ Song
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
#album ⇒ Object
Returns the value of attribute album.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def album @album end |
#artist ⇒ Object
Returns the value of attribute artist.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def artist @artist end |
#capo ⇒ Object
Returns the value of attribute capo.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def capo @capo end |
#custom ⇒ Object
Returns the value of attribute custom.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def custom @custom end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def key @key end |
#sections ⇒ Object
Returns the value of attribute sections.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def sections @sections end |
#tempo ⇒ Object
Returns the value of attribute tempo.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def tempo @tempo end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def title @title end |
#tuning ⇒ Object
Returns the value of attribute tuning.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def tuning @tuning end |
#year ⇒ Object
Returns the value of attribute year.
7 8 9 |
# File 'lib/song_pro/song.rb', line 7 def year @year end |
Instance Method Details
#chords ⇒ Object
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_html ⇒ Object
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 |