WillsItunesProject 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
@@ -2,6 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
+ bin/wills_itunes_project.rb
5
6
  lib/wills_itunes_project.rb
6
7
  test/iTunes Music Library.xml
7
8
  test/test_wills_itunes_project.rb
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'wills_itunes_project'
5
+
6
+ if $0 == __FILE__ then
7
+ db = WillsItunesProject.new ARGV.shift
8
+
9
+ p db.titles
10
+ p db.albums
11
+ p db.artists
12
+ p db.total_playtime
13
+ p db.most_played
14
+ p db.top_rated
15
+ p db.high_bit_rate
16
+ p db.one_hit_albums
17
+ p db.poser
18
+ p db.denial
19
+
20
+ end
@@ -3,7 +3,7 @@ require 'open-uri'
3
3
  require 'nokogiri'
4
4
 
5
5
  class WillsItunesProject
6
- VERSION = '1.0.1'
6
+ VERSION = '1.0.2'
7
7
 
8
8
  attr_accessor :tracks, :albums #, :movies, :tv_shows, :podcasts
9
9
 
@@ -25,9 +25,9 @@ class WillsItunesProject
25
25
  track = Track.new
26
26
  song.children.each do |key|
27
27
  case key.text
28
- when 'Artist' then track.artist = key.next.text
29
- when 'Name' then track.name = key.next.text
30
- when 'Album' then track.album = key.next.text
28
+ when 'Artist' then track.artist = key.next.text.to_s
29
+ when 'Name' then track.name = key.next.text.to_s
30
+ when 'Album' then track.album = key.next.text.to_s
31
31
  when 'Total Time' then track.time = key.next.text.to_i
32
32
  when 'Year' then track.year = key.next.text.to_i
33
33
  when 'Bit Rate' then track.bit_rate = key.next.text.to_i
@@ -35,6 +35,9 @@ class WillsItunesProject
35
35
  when 'Rating' then track.rating = key.next.text.to_i
36
36
  end
37
37
  end
38
+ track.bit_rate = 0 unless track.bit_rate
39
+ track.rating = 0 unless track.rating
40
+ track.play_count = 0 unless track.play_count
38
41
  @tracks << track
39
42
  if @albums[track.album]
40
43
  @albums[track.album] << track
@@ -77,18 +80,18 @@ class WillsItunesProject
77
80
  end
78
81
 
79
82
  def most_played num = 10
80
- @tracks.sort_by {|track| track.play_count.to_i || 0}.reverse.first(num)
83
+ @tracks.sort_by {|track| -track.play_count}.first(num)
81
84
  end
82
85
 
83
86
  def top_rated num = 10
84
- @tracks.sort_by {|track| track.rating.to_i || 0}.reverse.first(num)
87
+ @tracks.sort_by {|track| -track.rating}.first(num)
85
88
  end
86
89
 
87
90
  def high_bit_rate num = 10
88
- @tracks.sort_by {|track| track.bit_rate.to_i || 0}.reverse.first(num)
91
+ @tracks.sort_by {|track| -track.bit_rate}.first(num)
89
92
  end
90
93
 
91
- def one_hit_albums
94
+ def one_hit_albums
92
95
  one_hit_wonders = []
93
96
  @albums.each do |album, tracks|
94
97
  tracks_played = tracks.reject {|track| track.play_count == 0}
@@ -99,16 +102,18 @@ class WillsItunesProject
99
102
  one_hit_wonders
100
103
  end
101
104
 
102
- def poser
103
- # songs you've rated 3+ but never listen to
104
- # output lyrics to rock 'n roll lifestyle as joke
105
+ def poser # highly rated but never played
105
106
  @tracks.reject { |track|
106
- track.play_count.nil? || track.play_count > 0
107
+ track.play_count > 0
107
108
  }.reject { |track|
108
109
  track.rating < 40
109
110
  }
110
111
  end
111
112
 
112
-
113
+ def denial # most played but low rating
114
+ most_played.reject do |track|
115
+ track.rating > 40
116
+ end
117
+ end
113
118
 
114
119
  end
@@ -71,4 +71,11 @@ class TestWillsItunesProject < Test::Unit::TestCase
71
71
  end
72
72
  end
73
73
 
74
+ def test_denial
75
+ @@itunes.denial.each do |track|
76
+ assert 40 > track.rating, "#{track.rating} should be below 40"
77
+ assert @@itunes.most_played.include?(track), "most_played should include #{track.name}"
78
+ end
79
+ end
80
+
74
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: WillsItunesProject
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Larson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  Ev3A1Q==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-12-17 00:00:00 -08:00
33
+ date: 2008-12-22 00:00:00 -08:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -56,8 +56,8 @@ dependencies:
56
56
  description: Reads itunes data from itunes library XML files and provides useful information regarding the data within.
57
57
  email:
58
58
  - wlarson@gmail.com
59
- executables: []
60
-
59
+ executables:
60
+ - wills_itunes_project.rb
61
61
  extensions: []
62
62
 
63
63
  extra_rdoc_files:
@@ -69,6 +69,7 @@ files:
69
69
  - Manifest.txt
70
70
  - README.txt
71
71
  - Rakefile
72
+ - bin/wills_itunes_project.rb
72
73
  - lib/wills_itunes_project.rb
73
74
  - test/iTunes Music Library.xml
74
75
  - test/test_wills_itunes_project.rb
metadata.gz.sig CHANGED
Binary file