Class: RapGenius::Song
- Inherits:
-
Object
show all
- Includes:
- Scraper
- Defined in:
- lib/rapgenius/song.rb
Constant Summary
Constants included
from Scraper
RapGenius::Scraper::BASE_URL
Instance Attribute Summary
Attributes included from Scraper
#url
Instance Method Summary
collapse
Methods included from Scraper
#document
Constructor Details
#initialize(path) ⇒ Song
Returns a new instance of Song.
6
7
8
|
# File 'lib/rapgenius/song.rb', line 6
def initialize(path)
self.url = path
end
|
Instance Method Details
#annotations ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/rapgenius/song.rb', line 32
def annotations
@annotations ||= document.css('.lyrics a').map do |a|
Annotation.new(
id: a.attr('data-id').to_s,
song: self,
lyric: a.text
)
end
end
|
#artist ⇒ Object
10
11
12
|
# File 'lib/rapgenius/song.rb', line 10
def artist
document.css('.song_title a').text
end
|
#description ⇒ Object
18
19
20
|
# File 'lib/rapgenius/song.rb', line 18
def description
document.css('.description_body').text
end
|
#full_artist ⇒ Object
27
28
29
30
|
# File 'lib/rapgenius/song.rb', line 27
def full_artist
document.css('meta[property="og:title"]').attr('content').to_s.
split(" – ").first
end
|
#images ⇒ Object
22
23
24
25
|
# File 'lib/rapgenius/song.rb', line 22
def images
document.css('meta[property="og:image"]').
map { |meta| meta.attr('content') }
end
|
#title ⇒ Object
14
15
16
|
# File 'lib/rapgenius/song.rb', line 14
def title
document.css('.edit_song_description i').text
end
|