Class: Runoff::Commands::Chat

Inherits:
Command
  • Object
show all
Defined in:
lib/runoff/commands/chat.rb

Class Method Summary collapse

Methods inherited from Command

get_composition, get_destination, list_chatnames, print_result, try_to_archive

Class Method Details

.process(args, options = {}) ⇒ Object

Public: Exports specified chats.

args - Array containing skype username options - Hash containing user provided options

Examples

Chat.process ['username'], { from: '~/main.db' }


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

def self.process(args, options = {})
  if args.empty? && !options.has_key?('from')
    raise ArgumentError.new 'You must specify a username or a --from option'
  end

  composition = self.get_composition args[0], options[:from]
  destination = self.get_destination options[:destination]
  chatnames, raw_chatnames = composition.get_chatnames

  self.list_chatnames chatnames
  indecies = ask 'Which chats do you want to export? (Enter indecies) ', Array
  indecies = indecies.map { |index| index.to_i }
  selected_chatnames = []

  indecies.each { |index| selected_chatnames << raw_chatnames[index] }
  self.print_result composition.export_chats(selected_chatnames, destination)
  self.try_to_archive destination, options

rescue ArgumentError => e
  puts e
rescue IOError => e
  puts e
end