Sha256: bd6a7044be6b8bc08929ff14c274984bdf8471760818074d9a4f2793dcd57b91

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module AppleMusic
  class Album < Resource
    # https://developer.apple.com/documentation/applemusicapi/albums/attributes
    class Attributes
      attr_reader :album_name, :artist_name, :artwork, :content_rating,
                  :copyright, :editorial_notes, :genre_names, :is_complete,
                  :is_single, :name, :play_params, :record_label, :release_date,
                  :track_count, :url, :is_mastered_for_itunes, :upc

      def initialize(props = {})
        @album_name = props['albumName'] # required
        @artist_name = props['artistName'] # required
        @artwork = Artwork.new(props['artwork']) if props['artwork']
        @content_rating = props['contentRating']
        @copyright = props['copyright']
        @editorial_notes = EditorialNotes.new(props['editorialNotes']) if props['editorialNotes']
        @genre_names = props['genreNames'] # required
        @is_complete = props['isComplete'] # required
        @is_single = props['isSingle'] # required
        @name = props['name'] # required
        @play_params = PlayParameters.new(props['playParams']) if props['playParams']
        @record_label = props['recordLabel'] # required
        @release_date = begin # required
                          Date.parse(props['releaseDate'])
                        rescue ArgumentError
                          Date.parse("#{props['releaseDate']}/01/01")
                        end
        @track_count = props['trackCount'] # required
        @url = props['url'] # required
        @is_mastered_for_itunes = props['isMasteredForItunes'] # required
        @upc = props['upc']
      end

      def complete?
        is_complete
      end

      def single?
        is_single
      end

      def mastered_for_itunes?
        is_mastered_for_itunes
      end
    end

    self.attributes_model = self::Attributes
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
apple_music-0.3.1 lib/apple_music/album/attributes.rb
apple_music-0.3.0 lib/apple_music/album/attributes.rb