Class: Runoff::Commandline::Some

Inherits:
Command
  • Object
show all
Defined in:
lib/runoff/commandline/some.rb

Overview

Public: A command class that is used to export specified chat history.

Examples

command = Some.new { archive: true }
command.execute [ 'skype_username' ]

Instance Attribute Summary

Attributes inherited from Command

#parser

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Some

Public: initialize a new All command object.

options - A Hash of commandline options (default { archive: true }).



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/runoff/commandline/some.rb', line 17

def initialize(options = {})
  @options = options
  @parser = OptionParser.new do |opts|
    opts.banner = 'Exports specified chats: runoff some [SKYPE_USERNAME] [OPTIONS]'
    opts.on '-h', '--help', 'Displays help' do
      puts opts
      exit
    end

    opts.on '-f', '--from PATH', 'Specifies the location of the database file (main.db)' do |path|
      @options[:from] = path
    end

    opts.on '-d', '--destination PATH', 'Changes the default path for the exported files' do |path|
      @options[:destination] = path
    end

    opts.on '-a', '--[no-]archive', 'Toggles archiving feature' do |enable|
      @options[:archive] = enable
    end

    opts.on '-A', '--adapter [NAME]', 'Uses a specific file type adapter' do |adapter|
      @options[:adapter] = adapter.capitalize + 'Adapter'
    end
  end
end

Instance Method Details

#execute(args) ⇒ Object

Public: executes the command.

args - An Array of commandline arguments.



47
48
49
50
51
52
53
54
55
56
# File 'lib/runoff/commandline/some.rb', line 47

def execute(args)
  super args do |chat, file_writer|
    ids      = prompt_for_chatnames chat
    messages = chat.get_messages

    selected_messages = messages.keep_if { |m| ids.include? m[Runoff::COLUMNS[0]] }

    file_writer.write selected_messages
  end
end

#prompt_for_chatnames(chat) ⇒ Object

Public: Asks user to specify, which chats to export.

chat - A Chat object.

Examples

get_requested_chatnames Chat.new('/path/to/main.db')
# => [120, 86, 201]

Returns an Array of conversation ids.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/runoff/commandline/some.rb', line 68

def prompt_for_chatnames(chat)
  puts 'Specify numbers of the chats that you want to export (e.g., 201, 86, 120)'
  puts

  chat.get_chatname_options.each do |opt|
    puts "[#{opt[:id]}] #{opt[:name]}"
  end

  puts
  print "Numbers: "
  options = STDIN.gets # NOTE: For some reason just gets throws an error here.

  options.split(',').map(&:to_i)
end