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



70
71
72
# File 'lib/cem_acpt/goss/api/action_response.rb', line 70

def duration
  @duration
end

#roundObject

Returns the value of attribute round

Returns:

  • (Object)

    the current value of round



70
71
72
# File 'lib/cem_acpt/goss/api/action_response.rb', line 70

def round
  @round
end

#unitObject

Returns the value of attribute unit

Returns:

  • (Object)

    the current value of unit



70
71
72
# File 'lib/cem_acpt/goss/api/action_response.rb', line 70

def unit
  @unit
end

Instance Method Details

#to_fObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cem_acpt/goss/api/action_response.rb', line 71

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cem_acpt/goss/api/action_response.rb', line 88

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