Class: BioDSL::Command
- Inherits:
-
Object
- Object
- BioDSL::Command
- Defined in:
- lib/BioDSL/command.rb
Overview
Command class for initiating and calling commands.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#run_status ⇒ Object
Returns the value of attribute run_status.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#calc_delta ⇒ BioDSL::Status
Locate all status key pairs <foo>_in and <foo>_out and add a new status key <foo>_delta with the numerical difference.
-
#calc_time_elapsed ⇒ BioDSL::Status
Add a key with time_elapsed to the status.
-
#call(*args) ⇒ Object
Callback method for executing a Command lambda.
-
#initialize(name, lmb, options) ⇒ Command
constructor
Constructor for Command objects.
-
#to_s ⇒ String
Return string representation of a Command object.
Constructor Details
#initialize(name, lmb, options) ⇒ Command
Constructor for Command objects.
37 38 39 40 41 42 43 |
# File 'lib/BioDSL/command.rb', line 37 def initialize(name, lmb, ) @name = name @lmb = lmb @run_status = 'running' @options = @status = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/BioDSL/command.rb', line 29 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/BioDSL/command.rb', line 29 def @options end |
#run_status ⇒ Object
Returns the value of attribute run_status.
30 31 32 |
# File 'lib/BioDSL/command.rb', line 30 def run_status @run_status end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
29 30 31 |
# File 'lib/BioDSL/command.rb', line 29 def status @status end |
Instance Method Details
#calc_delta ⇒ BioDSL::Status
Locate all status key pairs <foo>_in and <foo>_out and add a new status key <foo>_delta with the numerical difference.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/BioDSL/command.rb', line 92 def calc_delta @status.keys.select { |s| s[-3..-1] == '_in' }.each do |in_key| base = in_key[0...-3] out_key = "#{base}_out".to_sym next unless @status.key? out_key @status["#{base}_delta".to_sym] = delta(in_key, out_key) @status["#{base}_delta_percent".to_sym] = delta_percent(in_key, out_key) end self end |
#calc_time_elapsed ⇒ BioDSL::Status
Add a key with time_elapsed to the status.
81 82 83 84 85 86 |
# File 'lib/BioDSL/command.rb', line 81 def calc_time_elapsed delta = @status[:time_stop] - @status[:time_start] @status[:time_elapsed] = (Time.mktime(0) + delta).strftime('%H:%M:%S') self end |
#call(*args) ⇒ Object
Callback method for executing a Command lambda.
48 49 50 51 52 53 54 55 |
# File 'lib/BioDSL/command.rb', line 48 def call(*args) @lmb.call(*args, @status) @run_status = 'done' @status[:time_stop] = Time.now calc_time_elapsed calc_delta end |
#to_s ⇒ String
Return string representation of a Command object.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/BioDSL/command.rb', line 60 def to_s = [] @options.each do |key, value| << case value.class.to_s when 'String' value = Regexp.quote(value) if key == :delimiter %(#{key}: "#{value}") when 'Symbol' "#{key}: :#{value}" else "#{key}: #{value}" end end @options.empty? ? @name : "#{@name}(#{.join(', ')})" end |