Class: Microphite::Metric
- Inherits:
-
Object
- Object
- Microphite::Metric
- Defined in:
- lib/microphite/metric.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key, value, time = nil) ⇒ Metric
constructor
A new instance of Metric.
Constructor Details
#initialize(key, value, time = nil) ⇒ Metric
Returns a new instance of Metric.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/microphite/metric.rb', line 5 def initialize(key, value, time=nil) raise(ArgumentError, 'key cannot be nil') if key.nil? raise(ArgumentError, 'value cannot be nil') if value.nil? @key = key.to_s @value = to_f! value if time.nil? @time = Time.now.to_f else @time = to_f! time end raise(ArgumentError, "invalid key: #{key}") if @key.empty? raise(ArgumentError, "invaild value: #{value} ") if @value.nil? raise(ArgumentError, "invalue time: #{time}") if @time.nil? end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/microphite/metric.rb', line 3 def key @key end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/microphite/metric.rb', line 3 def time @time end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/microphite/metric.rb', line 3 def value @value end |