Class: Helium::DataPoint
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Resource
Instance Method Summary collapse
- #aggregate? ⇒ Boolean
- #as_json ⇒ Object
- #avg ⇒ Object
-
#initialize(opts = {}) ⇒ DataPoint
constructor
A new instance of DataPoint.
- #max ⇒ Object
- #min ⇒ Object
Methods inherited from Resource
#==, all, all_path, create, #created_at, #destroy, #eql?, find, #hash, initialize_from_path, #metadata, resource_name, #resource_name, #resource_path, singleton, #to_json, #update, #updated_at
Methods included from Utils
Constructor Details
#initialize(opts = {}) ⇒ DataPoint
Returns a new instance of DataPoint
5 6 7 8 9 10 11 |
# File 'lib/helium/data_point.rb', line 5 def initialize(opts = {}) super(opts) @timestamp = @params.dig("attributes", "timestamp") @value = @params.dig("attributes", "value") @port = @params.dig("attributes", "port") end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port
3 4 5 |
# File 'lib/helium/data_point.rb', line 3 def port @port end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
3 4 5 |
# File 'lib/helium/data_point.rb', line 3 def @timestamp end |
#value ⇒ Object (readonly)
Returns the value of attribute value
3 4 5 |
# File 'lib/helium/data_point.rb', line 3 def value @value end |
Instance Method Details
#aggregate? ⇒ Boolean
32 33 34 |
# File 'lib/helium/data_point.rb', line 32 def aggregate? [max, min, avg].none? { |agg_value| agg_value.nil? } end |
#as_json ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/helium/data_point.rb', line 36 def as_json j = super.merge({ timestamp: , port: port }) if aggregate? j[:max] = max j[:min] = min j[:avg] = avg else j[:value] = value end j end |
#avg ⇒ Object
27 28 29 30 |
# File 'lib/helium/data_point.rb', line 27 def avg return nil unless @value.is_a?(Hash) @value["avg"] end |
#max ⇒ Object
17 18 19 20 |
# File 'lib/helium/data_point.rb', line 17 def max return nil unless @value.is_a?(Hash) @value["max"] end |
#min ⇒ Object
22 23 24 25 |
# File 'lib/helium/data_point.rb', line 22 def min return nil unless @value.is_a?(Hash) @value["min"] end |