Class: RapGenius::Line
Constant Summary
Constants included from Client
Client::BASE_URL, Client::DOM_TEXT_FORMAT, Client::PLAIN_TEXT_FORMAT
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes included from Client
Class Method Summary collapse
Instance Method Summary collapse
- #annotated? ⇒ Boolean (also: #explained?)
-
#explanations ⇒ Object
(also: #annotations)
A line can have multiple annotations, usually if it has a community one and a verified one.
-
#initialize(kwargs) ⇒ Line
constructor
A new instance of Line.
- #lyric ⇒ Object
- #response ⇒ Object
- #song ⇒ Object
Methods included from Client
Constructor Details
#initialize(kwargs) ⇒ Line
Returns a new instance of Line.
11 12 13 14 15 16 |
# File 'lib/rapgenius/line.rb', line 11 def initialize(kwargs) @id = kwargs.delete(:id) @song = kwargs.delete(:song) @lyric = kwargs.delete(:lyric) self.url = "referents/#{@id}" if @id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/rapgenius/line.rb', line 5 def id @id end |
Class Method Details
.find(id) ⇒ Object
7 8 9 |
# File 'lib/rapgenius/line.rb', line 7 def self.find(id) self.new(id: id).tap { |line| line.document } end |
Instance Method Details
#annotated? ⇒ Boolean Also known as: explained?
31 32 33 |
# File 'lib/rapgenius/line.rb', line 31 def annotated? !!@id end |
#explanations ⇒ Object Also known as: annotations
A line can have multiple annotations, usually if it has a community one and a verified one. Ideally, these would be encapsulated into an Annotation class, but I don’t have time for now.
40 41 42 43 44 45 46 |
# File 'lib/rapgenius/line.rb', line 40 def explanations return nil unless @id @explanation ||= response["annotations"].map do |annotation| annotation["body"]["plain"] end end |
#lyric ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rapgenius/line.rb', line 23 def lyric if @id @lyric ||= response["fragment"] else @lyric end end |
#response ⇒ Object
18 19 20 21 |
# File 'lib/rapgenius/line.rb', line 18 def response return nil unless @id document["response"]["referent"] end |