Class: AppleBot::CommandOptionSet

Inherits:
Struct
  • Object
show all
Defined in:
lib/applebot/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(required, optional) ⇒ CommandOptionSet

Returns a new instance of CommandOptionSet.


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/applebot/commands.rb', line 34

def initialize(required, optional)
  fix_batch_options = lambda { |set, extras|
    set.map {|o|
      if o['batch']
        o['keys'].map {|k|
          h = {
            'key' => k
          }.merge(o)
          h.delete 'keys'
          h.delete 'batch'
          h
        }
      else
        o
      end
    }.flatten.map {|o|
      o = o.merge(extras)
      CommandOption.new(o['key'], o['description'], o['values'], o['default'], o['required'])
    }
  }
  required = fix_batch_options.call(required, {'required' => true}) if required
  required ||= []
  optional = fix_batch_options.call(optional, {'required' => false}) if optional
  optional ||= []
  super(required, optional)
end

Instance Attribute Details

#optionalObject

Returns the value of attribute optional

Returns:

  • (Object)

    the current value of optional


33
34
35
# File 'lib/applebot/commands.rb', line 33

def optional
  @optional
end

#requiredObject

Returns the value of attribute required

Returns:

  • (Object)

    the current value of required


33
34
35
# File 'lib/applebot/commands.rb', line 33

def required
  @required
end