Class: Comcalc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/comcalc/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/comcalc/client.rb', line 11

def initialize(argv)
  @options = {}
  @argv = argv
  extract_options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/comcalc/client.rb', line 9

def options
  @options
end

Instance Method Details

#execute!Object



17
18
19
20
21
22
23
24
25
# File 'lib/comcalc/client.rb', line 17

def execute!
  cli = Comcalc::Cli
  if @options[:add]
    cli.new.menu
  else
    puts @optparse
    exit
  end
end

#extract_optionsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/comcalc/client.rb', line 27

def extract_options
  @optparse = OptionParser.new do |opts|
    opts.banner = "Usage: comcalc [options] ..."
    @options[:add] = false
    opts.on( '-m', '--menu', 'Add ip to your Connection list' )
      @options[:add] = true
    opts.on( '-h', '--help', 'Display this screen' ) do
      puts opts
      exit
    end
    opts.on( '-v', '--version', 'Print programs version' ) do
      puts Comcalc::VERSION
      exit
    end
  end
  @optparse.parse(@argv)
end