class RapGenius::Line

Attributes

id[R]

Public Class Methods

find(id) click to toggle source
# File lib/rapgenius/line.rb, line 7
def self.find(id)
  self.new(id: id).tap { |line| line.document }
end
new(kwargs) click to toggle source
# 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

Public Instance Methods

annotated?() click to toggle source
# File lib/rapgenius/line.rb, line 31
def annotated?
  !!@id
end
Also aliased as: explained?
annotations()
Alias for: explanations
explained?()
Alias for: annotated?
explanations() click to toggle source

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.

# File lib/rapgenius/line.rb, line 40
def explanations
  return nil unless @id

  @explanation ||= response["annotations"].map do |annotation|
    annotation["body"]["plain"]
  end
end
Also aliased as: annotations
lyric() click to toggle source
# File lib/rapgenius/line.rb, line 23
def lyric
  if @id
    @lyric ||= response["fragment"]
  else
    @lyric
  end
end
response() click to toggle source
# File lib/rapgenius/line.rb, line 18
def response
  return nil unless @id
  document["response"]["referent"]
end
song() click to toggle source
# File lib/rapgenius/line.rb, line 50
def song
  if @id
    @song ||= Song.find(response['song_id'])
  else
    @song
  end
end