Class: Vnehm::GetCommand

Inherits:
Command show all
Defined in:
lib/vnehm/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
# File 'lib/vnehm/commands/get_command.rb', line 6

def initialize
  super

  add_option(:to, 'to ПУТЬ',
             'Скачать аудиозапись(и) в ПУТЬ')

  add_option(:pl, 'pl ПЛЕЙЛИСТ',
             'Добавлять аудиозапись(и) в плейлист iTunes с именем ПЛЕЙЛИСТ')
end

Instance Method Details

#argumentsObject



36
37
38
# File 'lib/vnehm/commands/get_command.rb', line 36

def arguments
    { 'ЧИСЛО' => '(Необязательно) Скачать последние ЧИСЛО ваших аудиозаписей' }
end

#executeObject



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

def execute
  track_manager = TrackManager.new(@options)

  UI.say 'Получение информации об аудиозаписи(ях)'
  arg = @options[:args].pop
  tracks =
    case arg
      when /^\d$/ # If arg is number
        track_manager.tracks(arg, 0)
      when nil
        track_manager.tracks(*FIRST_TRACK)
      else
        UI.term "Введен некорректный аргумент"
    end

  UI.term 'У Вас ещё нет аудиозаписей' if tracks.nil?

  track_manager.process_tracks(tracks)
end

#program_nameObject



40
41
42
# File 'lib/vnehm/commands/get_command.rb', line 40

def program_name
  'vnehm get'
end

#summaryObject



44
45
46
# File 'lib/vnehm/commands/get_command.rb', line 44

def summary
  'Загрузка и добавление треков из VK в Вашу библиотеку iTunes'
end

#usageObject



48
49
50
# File 'lib/vnehm/commands/get_command.rb', line 48

def usage
  "#{program_name} [ЧИСЛО] [ОПЦИИ]"
end