Class: Runoff::Commandline::Some
- 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
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Public: executes the command.
-
#initialize(options = {}) ⇒ Some
constructor
Public: initialize a new All command object.
-
#prompt_for_chatnames(chat) ⇒ Object
Public: Asks user to specify, which chats to export.
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 = @parser = OptionParser.new do |opts| opts. = '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 = chat. = .keep_if { |m| ids.include? m[Runoff::COLUMNS[0]] } file_writer.write end end |
#prompt_for_chatnames(chat) ⇒ Object
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..each do |opt| puts "[#{opt[:id]}] #{opt[:name]}" end puts print "Numbers: " = STDIN.gets # NOTE: For some reason just gets throws an error here. .split(',').map(&:to_i) end |