Class: Nehm::GetCommand

Inherits:
Command show all
Defined in:
lib/nehm/commands/get_command.rb

Constant Summary collapse

FIRST_TRACK =
[1, 0]

Instance Attribute Summary

Attributes inherited from Command

#options, #options_descs

Instance Method Summary collapse

Methods inherited from Command

#add_option, #handle_options, #invoke

Constructor Details

#initializeGetCommand

Returns a new instance of GetCommand.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nehm/commands/get_command.rb', line 6

def initialize
  super

  add_option(:from, 'from PERMALINK',
             'Get track(s) from user with PERMALINK')

  add_option(:to, 'to PATH',
             'Download track(s) to PATH')

  add_option(:pl, 'pl PLAYLIST',
             'Add track(s) to iTunes playlist with PLAYLIST name')
end

Instance Method Details

#argumentsObject



48
49
50
51
52
53
54
# File 'lib/nehm/commands/get_command.rb', line 48

def arguments
  { 'post'         => 'Get last post (track or repost) from your profile',
    'NUMBER posts' => 'Get last NUMBER posts from your profile',
    'like'         => 'Get your last like',
    'NUMBER likes' => 'Get your last NUMBER likes',
    'URL'          => 'Get track from entered URL' }
end

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nehm/commands/get_command.rb', line 19

def execute
  track_manager = TrackManager.new(@options)

  arg = @options[:args].pop
  tracks =
    case arg
    when /^l.*s$/
      count = @options[:args].pop.to_i
      track_manager.likes(count, 0)
    when /^p.*s$/
      count = @options[:args].pop.to_i
      track_manager.posts(count, 0)
    when /^l/
      track_manager.likes(*FIRST_TRACK)
    when /^p/
      track_manager.posts(*FIRST_TRACK)
    when /https:\/\/soundcloud.com\//
      track_manager.track_from_url(arg)
    when nil
      UI.term 'You must provide an argument'
    else
      UI.term "Invalid argument/option '#{arg}'"
    end

  UI.term 'There are no tracks yet' if tracks.nil?

  track_manager.process_tracks(tracks)
end

#program_nameObject



56
57
58
# File 'lib/nehm/commands/get_command.rb', line 56

def program_name
  'nehm get'
end

#summaryObject



60
61
62
# File 'lib/nehm/commands/get_command.rb', line 60

def summary
  'Download tracks, set tags and add to your iTunes library tracks from SoundCloud'
end

#usageObject



64
65
66
# File 'lib/nehm/commands/get_command.rb', line 64

def usage
  "#{program_name} ARGUMENT [OPTIONS]"
end