class Vagalume::Song
Attributes
id[RW]
language[RW]
lyric[RW]
name[RW]
url[RW]
Public Class Methods
new(song)
click to toggle source
# File lib/vagalume/song.rb, line 5 def initialize(song) @id = song["id"] @language = song["lang"] @url = song["url"] @lyric = song["text"] @name = song["name"] if translation? @name = get_name_from_lyric(@lyric) @lyric = remove_title(@lyric) end end
Public Instance Methods
translation?()
click to toggle source
# File lib/vagalume/song.rb, line 18 def translation? @name.nil? end
Private Instance Methods
get_name_from_lyric(lyric)
click to toggle source
# File lib/vagalume/song.rb, line 24 def get_name_from_lyric(lyric) title = lyric.lines.first title.gsub(/\[|\]|\n/, "") end
remove_empty_lines_from_beginning(lines)
click to toggle source
# File lib/vagalume/song.rb, line 41 def remove_empty_lines_from_beginning(lines) return lines unless lines.first.empty? || lines.first == "\n" lines.shift remove_empty_lines_from_beginning(lines) end
remove_title(lyric)
click to toggle source
This is necessary because, for translations, the song title comes with the lyric text. Also, the format is not always the same, sometimes it's just one line for the title, sometimes it's the title followed by some empty lines. Here we remove the first line and any following empty lines, so we have a consident API.
# File lib/vagalume/song.rb, line 34 def remove_title(lyric) lines = lyric.lines lines.shift lines = remove_empty_lines_from_beginning(lines) lines.join end