Class: Ankit::Command
- Inherits:
-
Object
- Object
- Ankit::Command
- Defined in:
- lib/ankit/command.rb
Direct Known Subclasses
CardHappeningCommand, ChallengeCommand, ComingCommand, EventTraversingCommand, FindCommand, HelloCommand, ListCommand, RoundCommand, TextReadingCommand
Constant Summary collapse
- COMMANDS =
[]
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
Class Method Summary collapse
- .available ⇒ Object
- .by_name ⇒ Object
- .command_name ⇒ Object
- .define_options(&block) ⇒ Object
- .option_spec ⇒ Object
Instance Method Summary collapse
-
#initialize(runtime, args = []) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(runtime, args = []) ⇒ Command
Returns a new instance of Command.
28 29 30 31 32 33 34 |
# File 'lib/ankit/command.rb', line 28 def initialize(runtime, args=[]) @runtime = runtime @options = {} @args = OptionParser.new do |spec| self.class.option_spec.call(spec, @options) if self.class.option_spec end.parse(args) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/ankit/command.rb', line 6 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/ankit/command.rb', line 6 def @options end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
6 7 8 |
# File 'lib/ankit/command.rb', line 6 def runtime @runtime end |
Class Method Details
.available ⇒ Object
10 11 12 |
# File 'lib/ankit/command.rb', line 10 def self.available COMMANDS.push(self) end |
.by_name ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ankit/command.rb', line 18 def self.by_name COMMANDS.inject({}) do |a, cls| a[cls.command_name] = cls a end end |
.command_name ⇒ Object
14 15 16 |
# File 'lib/ankit/command.rb', line 14 def self.command_name /(.*)\:\:(\w+)Command/.match(self.name).to_a[-1].downcase end |
.define_options(&block) ⇒ Object
25 |
# File 'lib/ankit/command.rb', line 25 def self.(&block) @option_spec = block end |
.option_spec ⇒ Object
26 |
# File 'lib/ankit/command.rb', line 26 def self.option_spec; @option_spec; end |