Class: Command

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

Direct Known Subclasses

Nop

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



2
3
4
# File 'lib/bidding/command.rb', line 2

def arguments
  @arguments
end

#commandlineObject

Returns the value of attribute commandline.



2
3
4
# File 'lib/bidding/command.rb', line 2

def commandline
  @commandline
end

#execution_dateObject

Returns the value of attribute execution_date.



2
3
4
# File 'lib/bidding/command.rb', line 2

def execution_date
  @execution_date
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/bidding/command.rb', line 2

def name
  @name
end

#userObject

Returns the value of attribute user.



2
3
4
# File 'lib/bidding/command.rb', line 2

def user
  @user
end

Class Method Details

.build(command, *args) ⇒ Object



22
23
24
# File 'lib/bidding/command.rb', line 22

def self.build(command, *args)
  args.select {|arg| arg.to_s }.insert(0, command).join " "
end

.camel_case(s) ⇒ Object



26
27
28
29
# File 'lib/bidding/command.rb', line 26

def self.camel_case(s)
  return s if s !~ /_/ && s =~ /[A-Z]+.*/
    s.split('_').map{|e| e.capitalize}.join
end

.parameters(*args) ⇒ Object



4
5
6
7
8
# File 'lib/bidding/command.rb', line 4

def self.parameters(*args)
  args.each do |arg|
    self.class_eval("def #{arg};arguments["+args.index(arg).to_s+"];end")  
  end
end

.parse(commandline, user, time) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bidding/command.rb', line 10

def self.parse(commandline, user, time)
  parts = commandline.split(" ")
  name = camel_case parts.shift
  command = Kernel.const_get(name).new
  command.name = name
  command.user = user
  command.arguments = parts
  command.execution_date = time
  command.commandline = commandline
  command
end

Instance Method Details

#executeObject



32
33
34
# File 'lib/bidding/command.rb', line 32

def execute
  raise 'execute method not implemented for class: ' + self.class.name
end

#replayObject



36
37
38
39
# File 'lib/bidding/command.rb', line 36

def replay
  @replay = true
  execute
end