Class: RapGenius::Annotation

Inherits:
Object
  • Object
show all
Includes:
Scraper
Defined in:
lib/rapgenius/annotation.rb

Constant Summary

Constants included from Scraper

Scraper::BASE_URL

Instance Attribute Summary collapse

Attributes included from Scraper

#url

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Scraper

#document

Constructor Details

#initialize(kwargs) ⇒ Annotation

Returns a new instance of Annotation.



11
12
13
14
15
16
# File 'lib/rapgenius/annotation.rb', line 11

def initialize(kwargs)
  @id = kwargs.delete(:id)
  @song = kwargs.delete(:song)
  @lyric = kwargs.delete(:lyric)
  self.url = @id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/rapgenius/annotation.rb', line 5

def id
  @id
end

#songObject (readonly)

Returns the value of attribute song.



5
6
7
# File 'lib/rapgenius/annotation.rb', line 5

def song
  @song
end

Class Method Details

.find(id) ⇒ Object



7
8
9
# File 'lib/rapgenius/annotation.rb', line 7

def self.find(id)
  self.new(id: id)
end

Instance Method Details

#explanationObject



23
24
25
26
# File 'lib/rapgenius/annotation.rb', line 23

def explanation
  @explanation ||= document.css('meta[property="rap_genius:body"]').
    attr('content').to_s
end

#lyricObject



18
19
20
21
# File 'lib/rapgenius/annotation.rb', line 18

def lyric
  @lyric ||= document.css('meta[property="rap_genius:referent"]').
    attr('content').to_s
end