Class: Atig::Command::Option

Inherits:
Command
  • Object
show all
Defined in:
lib/atig/command/option.rb

Instance Attribute Summary

Attributes inherited from Command

#api, #db, #gateway, #opts

Instance Method Summary collapse

Methods inherited from Command

#find_by_tid

Constructor Details

#initialize(*args) ⇒ Option

Returns a new instance of Option.



9
10
11
12
# File 'lib/atig/command/option.rb', line 9

def initialize(*args)
  super
  @methods = OpenStruct.instance_methods
end

Instance Method Details

#action(target, mesg, command, args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/atig/command/option.rb', line 16

def action(target, mesg, command, args)
  if args.empty?
    @opts.fields.
      map{|x| x.to_s }.
      sort.each do|name|
        yield "#{name} => #{@opts[name]}"
    end
  else
    _,name,value = mesg.split ' ', 3
    unless value then
      # show the value
      yield "#{name} => #{@opts.send name}"
    else
      # set the value
      @opts.send "#{name}=",::Atig::Option.parse_value(value)
      yield "#{name} => #{@opts.send name}"
    end
  end
end

#command_nameObject



14
# File 'lib/atig/command/option.rb', line 14

def command_name; %w(opt opts option options) end