class RubyDeezer::Album

Attributes

artist[RW]
id[RW]
image[RW]
name[RW]
nb_disks[RW]
nb_tracks[RW]
tracks[RW]
url[RW]
year[RW]

Public Class Methods

find(id, options = []) click to toggle source
# File lib/ruby_deezer/album.rb, line 11
def self.find(id, options = [])
  response = get("/lookup/album/", {:query => {:id => id, :output => 'json', :options => options.join(",")}})
  artist = response ? Album.init_from_hash(response['album']) : nil
end
init_from_hash(hash) click to toggle source
# File lib/ruby_deezer/album.rb, line 32
def self.init_from_hash(hash)
  return nil unless hash.is_a?(Hash)
  tracks = hash["tracks"] || {}
  tracks_array = tracks["track"] || []
  artist = hash["artist"] || {}
  Album.new.tap do |album|
    album.id = hash["id"].to_i
    album.name = hash["name"]
    album.url = hash["url"]
    album.image = hash["image"]
    album.nb_tracks = hash["nb_tracks"].to_i
    album.nb_disks = hash["nb_disks"].to_i
    album.year = hash["year"].to_i
    album.tracks = tracks_array.inject([]) {|arr, track| arr << Track.init_from_hash(track); arr}
    album.artist = Artist.init_from_hash(artist)
  end
end