Class: WebInvoice::CLI::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/web_invoice/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Params

Returns a new instance of Params.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/web_invoice/cli.rb', line 9

def initialize(args)
  opt = OptionParser.new
  opt.on('-c config-file', 'default: ~/.webinvoicerc') { |v| @config = YAML.load_file(v) }
  opt.on('-d download-dir','default: .' ) { |v| @download_to = v }
  opt.on('-s service', 'default: saison_card') { |v| @service_name = v }
  opt.on('-u user') { |v| @user = v }
  opt.on('-p password') { |v| @password = v }
  opt.parse! args
  @config ||= YAML.load_file(File.join(ENV['HOME'], '.webinvoicerc'))
  @service_name = lookup_master_service
  @service_config = symbolize_keys(@config['services'][@service_name])
  @service_config[:download_to] = @download_to if @download_to
  @service_config[:user] = @user if @user
  @service_config[:password] = @password if @password
end

Instance Attribute Details

#service_configObject (readonly)

Returns the value of attribute service_config.



24
25
26
# File 'lib/web_invoice/cli.rb', line 24

def service_config
  @service_config
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



24
25
26
# File 'lib/web_invoice/cli.rb', line 24

def service_name
  @service_name
end

Instance Method Details

#service_classObject



25
26
27
28
29
30
31
# File 'lib/web_invoice/cli.rb', line 25

def service_class
  begin
    eval "WebInvoice::#{service_name.split(/_/).map { |w| w.capitalize }.join('')}"
  rescue
    nil
  end
end