Class: CemAcpt::Goss::Api::DurationHandler::Duration
- Inherits:
-
Struct
- Object
- Struct
- CemAcpt::Goss::Api::DurationHandler::Duration
- Defined in:
- lib/cem_acpt/goss/api/action_response.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#round ⇒ Object
Returns the value of attribute round.
-
#unit ⇒ Object
Returns the value of attribute unit.
Instance Method Summary collapse
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration
72 73 74 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72 def duration @duration end |
#round ⇒ Object
Returns the value of attribute round
72 73 74 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72 def round @round end |
#unit ⇒ Object
Returns the value of attribute unit
72 73 74 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72 def unit @unit end |
Instance Method Details
#to_f ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 73 def to_f return @to_f if defined?(@to_f) return 0.0 if duration.nil? case unit when :nanoseconds @to_f = duration.to_f.round(round) when :milliseconds @to_f = (duration.to_f / 1_000_000).round(round) when :seconds @to_f = (duration.to_f / 1_000_000_000).round(round) else raise ArgumentError, "Invalid unit #{unit}, must be one of #{DURATION_UNITS}" end @to_f end |
#to_s ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cem_acpt/goss/api/action_response.rb', line 90 def to_s return @to_s if defined?(@to_s) case unit when :nanoseconds @to_s = "#{to_f}ns" when :milliseconds @to_s = "#{to_f}ms" when :seconds @to_s = "#{to_f}s" else raise ArgumentError, "Invalid unit #{unit}, must be one of #{DURATION_UNITS}" end @to_s end |