Sha256: 07309d968ae1b70454251574478b819ea19998cef40dfa11b1c19bf0551c2db9

Contents?: true

Size: 731 Bytes

Versions: 2

Compression:

Stored size: 731 Bytes

Contents

module RapGenius
  class Annotation
    include RapGenius::Scraper

    attr_reader :id, :song

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

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

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

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

    def song
      entry_path = document.css('meta[property="rap_genius:song"]').
        attr('content').to_s

      @song ||= Song.new(entry_path)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapgenius-0.0.2 lib/rapgenius/annotation.rb
rapgenius-0.0.1 lib/rapgenius/annotation.rb