Class: Command
- Inherits:
-
Object
- Object
- Command
- Defined in:
- lib/bidding/command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#commandline ⇒ Object
Returns the value of attribute commandline.
-
#execution_date ⇒ Object
Returns the value of attribute execution_date.
-
#name ⇒ Object
Returns the value of attribute name.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .build(command, *args) ⇒ Object
- .camel_case(s) ⇒ Object
- .parameters(*args) ⇒ Object
- .parse(commandline, user, time) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
2 3 4 |
# File 'lib/bidding/command.rb', line 2 def arguments @arguments end |
#commandline ⇒ Object
Returns the value of attribute commandline.
2 3 4 |
# File 'lib/bidding/command.rb', line 2 def commandline @commandline end |
#execution_date ⇒ Object
Returns the value of attribute execution_date.
2 3 4 |
# File 'lib/bidding/command.rb', line 2 def execution_date @execution_date end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/bidding/command.rb', line 2 def name @name end |
#user ⇒ Object
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
#execute ⇒ Object
32 33 34 |
# File 'lib/bidding/command.rb', line 32 def execute raise 'execute method not implemented for class: ' + self.class.name end |
#replay ⇒ Object
36 37 38 39 |
# File 'lib/bidding/command.rb', line 36 def replay @replay = true execute end |