Sha256: fd23bbf9d4d0afb93118cdcb30a036f88294c6c1d59b83d691075c78973abb28

Contents?: true

Size: 802 Bytes

Versions: 2

Compression:

Stored size: 802 Bytes

Contents

module ItunesApi
  module Music
    module Results
      # Wrapper for song search results.
      class Song
        attr_reader_init :data
        private :data

        def duration
          @duration ||= track_lenght(data['trackTimeMillis'])
        end

        def attributes
          [duration, name, number, streamable]
        end

        def name
          @name ||= data['trackName']
        end

        def number
          @number ||= data['trackNumber']
        end

        def streamable
          @streamable ||= data['isStreamable']
        end

        private

        def track_lenght(milliseconds)
          minutes, milliseconds = milliseconds.divmod(1000 * 60)
          seconds = milliseconds / 1000
          "#{minutes}:#{seconds}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itunes_api-2.1.0 lib/itunes_api/music/results/song.rb
itunes_api-2.0.0 lib/itunes_api/music/results/song.rb