Sha256: c0c7c64478a2e26c28a2d788f82a09860d7dfdb85272a94008bdd1a90e2603bd

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

require 'yaml'
require_relative 'song'
require_relative 'render_song'

module Songbook
  class GenerateSongFile
    attr_reader :input_path, :output_path, :verbose

    def initialize(input_path:, output_path:, verbose: false)
      @input_path = input_path
      @output_path = output_path
      @verbose = verbose
    end

    def call
      puts "Generating #{output_path}..." if verbose

      File.open(output_path, 'w') { |file| file.write(song_text) }
    end

    private

    def song_text
      @song_text ||= RenderSong.new(song).call
    end

    def song
      @song ||= Song.new(
        title: File.basename(input_path, '.yml'),
        details: song_data['details'],
        chords: song_data['chords'],
        lyrics: song_data['lyrics']
      )
    end

    def song_data
      @song_data ||= YAML.load_file(input_path)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
songbook-0.5.1 lib/songbook/generate_song_file.rb
songbook-0.3.1 lib/songbook/generate_song_file.rb
songbook-0.3.0 lib/songbook/generate_song_file.rb