Class: Mycommands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mycommands/models/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#paramsObject

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

#categoryObject



37
38
39
# File 'lib/mycommands/models/command.rb', line 37

def category
  @command[1][0]
end

#command_stringObject



41
42
43
# File 'lib/mycommands/models/command.rb', line 41

def command_string
  @command[1][1]
end

#descriptionObject



33
34
35
# File 'lib/mycommands/models/command.rb', line 33

def description
  @command[0]
end

#finished_commandObject



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

Returns:

  • (Boolean)


50
51
52
# File 'lib/mycommands/models/command.rb', line 50

def has_params?
  @has_params ||= @command[1].size > 2
end

#to_hashObject



64
65
66
# File 'lib/mycommands/models/command.rb', line 64

def to_hash
  {@command[0] => @command[1]}
end