Class: Lyriki::Legacy::SongLyrics

Inherits:
Object
  • Object
show all
Includes:
WebHelpers
Defined in:
lib/lyriki/legacy/song_lyrics.rb

Instance Method Summary collapse

Methods included from WebHelpers

#get

Constructor Details

#initialize(**args) ⇒ SongLyrics

Returns a new instance of SongLyrics.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/lyriki/legacy/song_lyrics.rb', line 11

def initialize(**args)
  raise ArgumentError unless args[:artist] && args[:song]
  song_data = SongData.new(args).response_data
  if song_data["lyrics"] == "Not found"
    raise NoLyricsError, "lyrics not found: #{song_data}"
  end

  @data = get(song_data["url"])
end

Instance Method Details

#response_dataObject



21
22
23
# File 'lib/lyriki/legacy/song_lyrics.rb', line 21

def response_data
  Nokogiri::HTML(@data).css("div.lyricbox/text()").map(&:text)
end