Sha256: 86556ba8c89df56e9897962dcf5c9ee759d556b65c3217d8b62cf94e7d44723e

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 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

    def formatted_title
      "[#{title}]"
    end

    private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
songbook-0.5.1 lib/songbook/verse.rb