Class: Lyricli::LyricsEngine
- Inherits:
-
Object
- Object
- Lyricli::LyricsEngine
- Includes:
- Util
- Defined in:
- lib/lyricli/lyrics_engine.rb
Instance Method Summary (collapse)
- - (Object) get_lyrics
-
- (LyricsEngine) initialize(artist, song)
constructor
A new instance of LyricsEngine.
Methods included from Util
#camelize, #parse_class, #sanitize_param
Constructor Details
- (LyricsEngine) initialize(artist, song)
A new instance of LyricsEngine
6 7 8 |
# File 'lib/lyricli/lyrics_engine.rb', line 6 def initialize(artist, song) @provider = URI("http://lyrics.wikia.com/api.php?artist=#{sanitize_param artist}&song=#{sanitize_param song}&fmt=realjson") end |
Instance Method Details
- (Object) get_lyrics
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lyricli/lyrics_engine.rb', line 10 def get_lyrics begin response = Net::HTTP.get(@provider) response = MultiJson.decode(response) doc = Nokogiri::HTML(open(response['url'])) node = doc.search(".lyricbox").first rescue raise Lyricli::LyricsNotFoundException end node.search(".rtMatcher").each do |n| n.remove end node.search("br").each do |br| br.replace "\n" end node.inner_text end |