Class: Tremolo::DataPoint
- Inherits:
-
Object
- Object
- Tremolo::DataPoint
- Defined in:
- lib/tremolo/data_point.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#series_name ⇒ Object
Returns the value of attribute series_name.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(series_name, columns, data) ⇒ DataPoint
constructor
A new instance of DataPoint.
- #points ⇒ Object
Constructor Details
#initialize(series_name, columns, data) ⇒ DataPoint
Returns a new instance of DataPoint.
9 10 11 12 13 14 |
# File 'lib/tremolo/data_point.rb', line 9 def initialize(series_name, columns, data) self.series_name = series_name self.columns = columns.sort @data = data end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
7 8 9 |
# File 'lib/tremolo/data_point.rb', line 7 def columns @columns end |
#series_name ⇒ Object
Returns the value of attribute series_name.
7 8 9 |
# File 'lib/tremolo/data_point.rb', line 7 def series_name @series_name end |
Class Method Details
.from_hash(series_name, h) ⇒ Object
3 4 5 |
# File 'lib/tremolo/data_point.rb', line 3 def self.from_hash(series_name, h) new(series_name, h.reduce(:merge).keys, h) end |
Instance Method Details
#as_json ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tremolo/data_point.rb', line 20 def as_json [{ name: series_name, columns: columns, points: points }] end |
#points ⇒ Object
16 17 18 |
# File 'lib/tremolo/data_point.rb', line 16 def points @points ||= @data.map {|h| h.values_at(*columns) } end |