Class: TheFox::Wallet::CsvCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/wallet/command_csv.rb

Overview

Import or export to/from CSV file format.

Constant Summary collapse

NAME =
'csv'

Instance Method Summary collapse

Methods inherited from Command

create_by_name, #initialize, is_matching_class

Constructor Details

This class inherits a constructor from TheFox::Wallet::Command

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wallet/command_csv.rb', line 9

def run
  if @options[:path].nil?
    raise "Option --path is required for command '#{NAME}'"
  end
  
  wallet = Wallet.new(@options[:wallet_path])
  wallet.logger = @options[:logger]
  
  # Import by default.
  if @options[:is_import] || !@options[:is_export]
    # Import
    @options[:logger].info("import csv #{@options[:path]} ...") if @options[:logger]
    wallet.import_csv_file(@options[:path])
    @options[:logger].info("import csv #{@options[:path]} done") if @options[:logger]
  elsif @options[:is_export]
    # Export
    @options[:logger].info("export csv #{@options[:path]} ...") if @options[:logger]
    wallet.export_csv_file(@options[:path])
    @options[:logger].info("export csv #{@options[:path]} done") if @options[:logger]
  end
end