class Songbook::Verse

Attributes

chords[R]
lyrics[R]
title[R]

Public Class Methods

new(title:, chords:, lyrics:) click to toggle source
# File lib/songbook/verse.rb, line 9
def initialize(title:, chords:, lyrics:)
  raise "Verse '#{title} chords is nil" if chords.nil?

  @title = title
  @chords = chords
  @lyrics = lyrics
end

Public Instance Methods

lines() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/songbook/verse.rb, line 18
def lines
  if lyric_lines.length != chord_lines.length
    raise "'#{title}' lyrics length doesn't match chords length:\n\n" \
      "#{lyric_lines}\n\nversus\n\n#{chord_lines}"
  end

  lyric_lines.map.with_index do |lyric_line, i|
    OpenStruct.new(lyrics: lyric_line, chords: chord_lines[i])
  end
end

Private Instance Methods

chord_lines() click to toggle source
# File lib/songbook/verse.rb, line 36
def chord_lines
  @chord_lines ||= chords.split("\n")
end
lyric_lines() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/songbook/verse.rb, line 32
def lyric_lines
  @lyric_lines ||= lyrics.split("\n")
end