Class: Chordproko::Line
- Inherits:
-
Object
- Object
- Chordproko::Line
- Defined in:
- lib/chordproko/line.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(content) ⇒ Line
constructor
A new instance of Line.
- #to_s ⇒ Object
Constructor Details
#initialize(content) ⇒ Line
Returns a new instance of Line.
4 5 6 |
# File 'lib/chordproko/line.rb', line 4 def initialize content @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/chordproko/line.rb', line 3 def content @content end |
Instance Method Details
#each(&block) ⇒ Object
8 9 10 |
# File 'lib/chordproko/line.rb', line 8 def each(&block) @content.each(&block) rescue [@content] end |
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chordproko/line.rb', line 11 def to_s case @content.class.to_s when "Chordproko::Comment" @content.to_s when "Chordproko::Directive" @content.to_s when "String" "" else chords = "" lyrics = "" prev_lyrics = "" @content.each do |c| case c.class.to_s when "Chordproko::ChordGroup" chords += " " * prev_lyrics.size + "#{c}" when "Chordproko::Lyric" prev_lyrics = "#{c}" lyrics += "#{c}" end end "#{chords}\n#{lyrics}" end end |