Class: CommandDesigner::Command
- Inherits:
-
Object
- Object
- CommandDesigner::Command
- Defined in:
- lib/command-designer/command.rb
Overview
A concpet of command that can be extended multiple times
Instance Attribute Summary collapse
-
#command ⇒ String
readonly
Current value of the command.
-
#initial_command ⇒ Array
readonly
Initial value of the command and parameters.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if other object equals command_name, false otherwise.
-
#change {|command| ... } ⇒ String
Yields a block to change the command.
-
#command_name ⇒ String
Just the first part of the command:
command_name. -
#initialize(*args) ⇒ Command
constructor
initialize
commandandinitial_command. -
#reset ⇒ Object
reset command to it’s initial state.
Constructor Details
#initialize(*args) ⇒ Command
initialize command and initial_command
28 29 30 31 |
# File 'lib/command-designer/command.rb', line 28 def initialize(*args) @initial_command = args || [] reset end |
Instance Attribute Details
#command ⇒ String (readonly)
Returns current value of the command.
21 22 23 |
# File 'lib/command-designer/command.rb', line 21 def command @command end |
#initial_command ⇒ Array (readonly)
Returns initial value of the command and parameters.
24 25 26 |
# File 'lib/command-designer/command.rb', line 24 def initial_command @initial_command end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other object equals command_name, false otherwise.
52 53 54 |
# File 'lib/command-designer/command.rb', line 52 def ==(other) self.command_name == other end |
#change {|command| ... } ⇒ String
Yields a block to change the command
42 43 44 |
# File 'lib/command-designer/command.rb', line 42 def change(&block) @command = yield @command end |
#command_name ⇒ String
Returns just the first part of the command: command_name.
47 48 49 |
# File 'lib/command-designer/command.rb', line 47 def command_name @initial_command.first end |
#reset ⇒ Object
reset command to it’s initial state
34 35 36 |
# File 'lib/command-designer/command.rb', line 34 def reset @command = Shellwords.join(@initial_command) end |