Sha256: 6d56277d03e1d62354d007583bd0862ee7b8bacb97e54be165bbaa6044e05561

Contents?: true

Size: 886 Bytes

Versions: 4

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

require 'ostruct'

module Songbook
  class Verse
    attr_reader :title, :chords, :lyrics

    def initialize(title:, chords:, lyrics:)
      raise "Verse '#{title} chords is nil" if chords.nil?

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

    # rubocop:disable Metrics/AbcSize
    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
    # rubocop:enable Metrics/AbcSize

    private

    def lyric_lines
      @lyric_lines ||= lyrics.split("\n")
    end

    def chord_lines
      @chord_lines ||= chords.split("\n")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
songbook-0.5.0 lib/songbook/verse.rb
songbook-0.4.0 lib/songbook/verse.rb
songbook-0.3.1 lib/songbook/verse.rb
songbook-0.3.0 lib/songbook/verse.rb