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
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Scraper
#document
Constructor Details
#initialize(path) ⇒ Song
Returns a new instance of Song.
10
11
12
|
# File 'lib/rapgenius/song.rb', line 10
def initialize(path)
self.url = path
end
|
Class Method Details
.find(path) ⇒ Object
6
7
8
|
# File 'lib/rapgenius/song.rb', line 6
def self.find(path)
self.new(path)
end
|
Instance Method Details
#annotations ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/rapgenius/song.rb', line 37
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
15
16
17
|
# File 'lib/rapgenius/song.rb', line 15
def artist
document.css('.song_title a').text
end
|
#description ⇒ Object
23
24
25
|
# File 'lib/rapgenius/song.rb', line 23
def description
document.css('.description_body').text
end
|
#full_artist ⇒ Object
32
33
34
35
|
# File 'lib/rapgenius/song.rb', line 32
def full_artist
document.css('meta[property="og:title"]').attr('content').to_s.
split(" – ").first
end
|
#images ⇒ Object
27
28
29
30
|
# File 'lib/rapgenius/song.rb', line 27
def images
document.css('meta[property="og:image"]').
map { |meta| meta.attr('content') }
end
|
#title ⇒ Object
19
20
21
|
# File 'lib/rapgenius/song.rb', line 19
def title
document.css('.edit_song_description i').text
end
|