Class: Mcoin::Command::Base::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/mcoin/command/base.rb

Overview

Option Register

Instance Method Summary collapse

Constructor Details

#initialize(mode, name, *args) ⇒ Option

Returns a new instance of Option.



46
47
48
49
50
# File 'lib/mcoin/command/base.rb', line 46

def initialize(mode, name, *args)
  @mode = mode
  @name = name.to_sym
  @args = args
end

Instance Method Details

#register(command) ⇒ Object



52
53
54
55
56
57
# File 'lib/mcoin/command/base.rb', line 52

def register(command)
  case @mode
  when :single then register_as_single(command)
  when :multiple then register_as_multiple(command)
  end
end

#register_as_multiple(command) ⇒ Object



63
64
65
66
# File 'lib/mcoin/command/base.rb', line 63

def register_as_multiple(command)
  command.option[@name] ||= []
  command.on(*@args, ->(value) { command.option[@name].push(value) })
end

#register_as_single(command) ⇒ Object



59
60
61
# File 'lib/mcoin/command/base.rb', line 59

def register_as_single(command)
  command.on(*@args, ->(value) { command.option[@name] = value })
end