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| case recording['type'] when 'youtube' song.recordings.push YouTubeRecording.new(recording['link']) when 'bandcamp' song.recordings.push BandcampRecording.new(recording['embed']) when 'soundcloud' song.recordings.push SoundCloudRecording.new(recording['embed']) 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