Class: Output

Inherits:
Object
  • Object
show all
Defined in:
lib/output.rb

Class Method Summary collapse

Class Method Details

.convert_time(milliseconds) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/output.rb', line 54

def self.convert_time(milliseconds)
  output = {}
  time = (milliseconds.to_f / 1000).round.to_i
  
  output[:days] = time / 86400
  output[:hours] = (time / 3600) - (output[:days] * 24)
  output[:minutes] = (time / 60) - (output[:days] * 1440) - (output[:hours] * 60)
  output[:seconds] = time % 60
  
  return output
end

.members(artist) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/output.rb', line 40

def self.members(artist)
  if artist.members == [] then
    if artist.realname == ""
      members = artist.name.to_a
    else
      members = artist.realname.to_a
    end
  else
    members = artist.members
    members[-1] = "and #{members.last}" if members.size > 1
  end
  return members
end

.run(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/output.rb', line 6

def self.run(args)
   if args.size == 0
     puts "USAGE: imine [path to itunes xml] [number of top tracks to list (optional, defaults to 10)]"
     return
   end
   @miner = Imine.new(args.first, 1)
   @artist = Discog.new(@miner.most_played(1).first[3])
   most_played_num = args[1].to_i == 0 ? 10 : args[1].to_i
   puts bold("Number of albums: ") + "#{@miner.number_of_albums}"
   puts
   puts bold("Number of artists: ") + "#{@miner.number_of_artists}"
   puts
   puts bold("Number of tracks: ") + "#{@miner.number_of_tracks}"
   puts
   puts "You have more music from the year " + bold("#{@miner.top_year}") + " than any other." unless @miner.top_year == ""
   puts
   time = convert_time(@miner.total_playtime)
   puts bold("Total playtime: ") + "#{time[:days]} days, #{time[:hours]} hours, #{time[:minutes]} minutes, and #{time[:seconds]} seconds."
   puts
   puts "Top " + bold("#{most_played_num}") + " most played tracks:"
   puts
   puts
   show_most_played(most_played_num)
   puts
   puts "Your most played track is by " + bold("#{@artist.name}")
   puts "Members of " + bold("#{@artist.name}") + " include: #{members(@artist).join(", ")}"
   unless @artist.profile == ""
     puts
     puts "Here is some information about " + bold("#{@artist.name}")
     puts
     puts @artist.profile.gsub("<P>", "\n\n").gsub(/<\/?[^>]+>/, "")
   end
end

.show_most_played(n) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/output.rb', line 66

def self.show_most_played(n)
  spaces = 10
  @miner.most_played(n).each do |item|
    artist_track = bold("#{item[3]}") + " - #{item[0]}"
    spaces = artist_track.length + 21 if artist_track.length > spaces
  end
  puts underscore(bold("%-#{spaces-8}s%s    %s")) % ["Artist - Track", "Times played", "Stars"]
  puts
  @miner.most_played(n).each do |item|
    artist_track = bold("#{item[3]}") + " - #{item[0]}"
    puts "%-#{spaces}s%s   %s" % [artist_track, green("#{item[1]}"), "#{" " * (13 - item[1].to_s.size)}" + @miner.get_stars(item[2], :visual)]
  end
end