require 'yaml' require './lib/recording' class Song attr_accessor :title, :id, :lyrics, :recordings def initialize title, id @title = title @id = id @recordings = [] end def self.from_yaml song_id metadata = YAML.load(File.read(src(song_meta song_id))) song = Song.new metadata['title'], song_id song.lyrics = nil lyrics_file = src (song_lyrics song_id) if File.file? lyrics_file song.lyrics = File.read lyrics_file end if metadata['recordings'] metadata['recordings'].each do |recording| if recording['type'] == 'youtube' song.recordings.push YouTubeRecording.new(recording['link']) elsif recording['type'] == 'bandcamp' song.recordings.push BandcampRecording.new(recording['link']) end end end song end def split_lyrics @lyrics.split("\n\n").map { |paragraph| paragraph.split "\n" } end def render_sheet_music if File.file? (src (song_ly id)) template = ERB.new(File.read('templates/sheet_music.html.erb'), trim_mode: '-') template.result binding else "" end end end