class Firstfm::Track

Attributes

artist[RW]
images[RW]
listeners[RW]
mbid[RW]
name[RW]
rank[RW]
streamable[RW]
url[RW]

Public Class Methods

init_from_array(array) click to toggle source
# File lib/firstfm/track.rb, line 21
def self.init_from_array(array)
  return [] unless array.is_a?(Array)
  array.inject([]) do |arr, track|
    arr << init_from_hash(track)
    arr
  end
end
init_from_hash(hash) click to toggle source
# File lib/firstfm/track.rb, line 29
def self.init_from_hash(hash)
  return nil unless hash.is_a?(Hash)
  Track.new.tap do |track|
    track.rank = hash["@attr"]["rank"].to_i if hash["@attr"]
    track.name = hash["name"]
    track.mbid = hash["mbid"].to_s.size > 0 ? hash["mbid"] : nil
    track.url = hash["url"]
    track.listeners = hash["listeners"].to_i
    track.streamable = false
    track.images = hash["image"]
    track.artist = hash["artist"].is_a?(Hash) ? Artist.init_from_hash(hash["artist"]) : Artist.new(:name => hash["artist"])
  end
end