Class: Mycommands::Command
- Inherits:
-
Object
- Object
- Mycommands::Command
- Defined in:
- lib/mycommands/models/command.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #category ⇒ Object
- #command_string ⇒ Object
- #description ⇒ Object
- #finished_command ⇒ Object
- #has_params? ⇒ Boolean
-
#initialize(command) ⇒ Command
constructor
A new instance of Command.
- #to_hash ⇒ Object
Constructor Details
#initialize(command) ⇒ Command
Returns a new instance of Command.
29 30 31 |
# File 'lib/mycommands/models/command.rb', line 29 def initialize command @command = command end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
27 28 29 |
# File 'lib/mycommands/models/command.rb', line 27 def params @params end |
Instance Method Details
#<=>(other) ⇒ Object
68 69 70 |
# File 'lib/mycommands/models/command.rb', line 68 def <=> other [self.category, self.description] <=> [other.category, other.description] end |
#category ⇒ Object
37 38 39 |
# File 'lib/mycommands/models/command.rb', line 37 def category @command[1][0] end |
#command_string ⇒ Object
41 42 43 |
# File 'lib/mycommands/models/command.rb', line 41 def command_string @command[1][1] end |
#description ⇒ Object
33 34 35 |
# File 'lib/mycommands/models/command.rb', line 33 def description @command[0] end |
#finished_command ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/mycommands/models/command.rb', line 54 def finished_command finished_command = command_string if has_params? @params.each do |param| finished_command = finished_command.gsub(param.value, param.substituted) end end finished_command end |
#has_params? ⇒ Boolean
50 51 52 |
# File 'lib/mycommands/models/command.rb', line 50 def has_params? @has_params ||= @command[1].size > 2 end |
#to_hash ⇒ Object
64 65 66 |
# File 'lib/mycommands/models/command.rb', line 64 def to_hash {@command[0] => @command[1]} end |