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.



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

def initialize
  super

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

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

Instance Method Details

#argumentsObject



38
39
40
# File 'lib/vnehm/commands/get_command.rb', line 38

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

#executeObject



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

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.to_i, 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



42
43
44
# File 'lib/vnehm/commands/get_command.rb', line 42

def program_name
  'vnehm get'
end

#summaryObject



46
47
48
# File 'lib/vnehm/commands/get_command.rb', line 46

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

#usageObject



50
51
52
# File 'lib/vnehm/commands/get_command.rb', line 50

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