Sha256: 9c5129efb2bd4c9375f96bb4a47ba9e27add5978cf8a232b8d86e455dd2d1371
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
require 'itunes/library' module Stratify module ITunes class Query attr_reader :library_path, :limit def initialize(library_path, limit = 50) @library_path = library_path @limit = limit end def activities recently_played_tracks.map {|track| build_activity_from_raw_data(track)} end private def library_xml open(@library_path).read end def build_activity_from_raw_data(track) Stratify::ITunes::Activity.new({ :album => track.album, :artist => track.artist, :composer => track.composer, :created_at => track.last_played_at.to_time, :episode_number => track.episode_number, :genre => track.genre, :movie => track.movie?, :name => track.name, :persistent_id => track.persistent_id, :podcast => track.podcast?, :season_number => track.season_number, :track_number => track.number, :tv_show => track.tv_show?, :year => track.year, }) end def tracks ::ITunes::Library.load(library_xml).tracks end def played_tracks tracks.select { |t| t.played? } end def recently_played_tracks sorted_tracks = played_tracks.sort_by(&:last_played_at) sorted_tracks.last(limit) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
stratify-itunes-0.1.3 | lib/stratify-itunes/query.rb |
stratify-itunes-0.1.2 | lib/stratify-itunes/query.rb |
stratify-itunes-0.1.0 | lib/stratify-itunes/query.rb |