class Chordproko::Line

Attributes

content[RW]

Public Class Methods

new(content) click to toggle source
# File lib/chordproko/line.rb, line 4
def initialize content
  @content = content
end

Public Instance Methods

each(&block) click to toggle source
# File lib/chordproko/line.rb, line 8
def each(&block)
  @content.each(&block) rescue [@content]
end
to_s() click to toggle source
# 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