Class: CemAcpt::Goss::Api::DurationHandler::Duration

Inherits:
Struct
  • Object
show all
Defined in:
lib/cem_acpt/goss/api/action_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#durationObject

Returns the value of attribute duration

Returns:

  • (Object)

    the current value of duration



72
73
74
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72

def duration
  @duration
end

#roundObject

Returns the value of attribute round

Returns:

  • (Object)

    the current value of round



72
73
74
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72

def round
  @round
end

#unitObject

Returns the value of attribute unit

Returns:

  • (Object)

    the current value of unit



72
73
74
# File 'lib/cem_acpt/goss/api/action_response.rb', line 72

def unit
  @unit
end

Instance Method Details

#to_fObject



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_sObject



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