Class: ItunesTrack::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/itunes_track/cli.rb

Instance Method Summary collapse

Instance Method Details

#csv(path) ⇒ Object



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

def csv(path)
  fields = options[:fields].split(",")
  cond =
    if options[:artist]
      ->t{ t.artist.get.match(/#{options[:artist]}/i) }
    else
      ->t{ true }
    end
  puts "I am working on csv..."
  ItunesTrack.build(*fields, &cond)
  ItunesTrack.to_csv(path, fields)
  puts "CSV file successfully created at #{path}."
end

#size(artist = nil) ⇒ Object



6
7
8
9
# File 'lib/itunes_track/cli.rb', line 6

def size(artist=nil)
  cond = artist ? ->t{ t.artist.get.match /#{artist}/i } : ->t{ true }
  puts ItunesTrack.size(&cond)
end

#tracksObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/itunes_track/cli.rb', line 14

def tracks
  artist, album = options[:artist], options[:album]
  if artist && album
    cond = ->t{ t.artist.get.match(/#{artist}/i) && t.album.get.match(/#{album}/i) }
  elsif artist
    cond = ->t{ t.artist.get.match(/#{artist}/i) }
  elsif album
    cond = ->t{ t.album.get.match(/#{album}/i) }
  else
    cond = ->t{ true }
  end
  attrs = %i(name time artist album played_count)
  res = ItunesTrack.itunes_tracks(&cond)
  unless res.empty?
    res.map { |t|
      puts attrs.inject("") { |str, attr| [str, t.send(attr).get.to_s].join(" ") }
    }
  else
    puts "No tracks found"
  end
end

#versionObject



54
55
56
# File 'lib/itunes_track/cli.rb', line 54

def version
  puts "ItunesTrack #{ItunesTrack::VERSION} (c) 2013 kyoendo"
end