Sha256: 79f2fa615d60750186afa07e8ac23d1b05a1808b10b5256c77a7551b7cc4a389
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true require 'date' module ItunesApi module Music # Wrapper for album results. class Album attr_reader_init :artist, :artwork, :collection_id, :explicitness, :genre, :link, :name, :release_on, :store, :track_count class << self def find_by_collection_id(collection_id, store) result = albums(collection_id, store).first new(*result.attributes) if result end def find_by_apple_id(apple_id, store) albums(apple_id, store).map { |album| new(*album.attributes) } end private def albums(id, store) Requests::Albums.find_by_id(id, store) end end def availability @availability ||= build_availability end def explicit? explicitness == 'explicit' end def to_hash { artist: artist, artwork: artwork, availability: availability, collection_id: collection_id, explicit: explicit?, genre: genre, link: link, name: name, release_on: release_on, store: store, track_count: track_count } end def tracklist @tracklist ||= Song.find_by_collection_id(collection_id, store) end private def apple_music? tracklist.any?(&:streamable?) end def build_availability prefix = pre_release? ? 'pre_release_' : '' suffix = apple_music? ? 'streaming' : 'sale' "#{prefix}#{suffix}".to_sym end def pre_release? release_on > Date.today end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
itunes_api-2.4.1 | lib/itunes_api/music/album.rb |
itunes_api-2.4.0 | lib/itunes_api/music/album.rb |
itunes_api-2.3.2 | lib/itunes_api/music/album.rb |