Class: DataSet
- Inherits:
-
Object
- Object
- DataSet
- Defined in:
- lib/data_set.rb
Direct Known Subclasses
DailyDataSet, DayOfWeekDataSet, HourOfDayDataSet, HourlyDataSet, MonthlyDataSet
Defined Under Namespace
Classes: DailyDataSet, DayOfWeekDataSet, HourOfDayDataSet, HourlyDataSet, MonthlyDataSet
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#datapoints ⇒ Object
Returns the value of attribute datapoints.
-
#max_date ⇒ Object
readonly
Returns the value of attribute max_date.
-
#max_value ⇒ Object
readonly
Returns the value of attribute max_value.
-
#min_date ⇒ Object
readonly
Returns the value of attribute min_date.
-
#min_value ⇒ Object
readonly
Returns the value of attribute min_value.
Instance Method Summary collapse
- #dates ⇒ Object
-
#initialize(point_array) ⇒ DataSet
constructor
The standard initialize function creates a hash out of an array of points.
- #value_for_date(date) ⇒ Object
- #values ⇒ Object
- #values_for_google_chart ⇒ Object
Constructor Details
#initialize(point_array) ⇒ DataSet
The standard initialize function creates a hash out of an array of points.
7 8 9 10 11 12 13 14 15 |
# File 'lib/data_set.rb', line 7 def initialize( point_array ) @datapoints ||= {} @count = count || 30 point_array.each do |x_value, y_value| y_value = y_value.to_f @datapoints[x_value] = y_value end end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
4 5 6 |
# File 'lib/data_set.rb', line 4 def count @count end |
#datapoints ⇒ Object
Returns the value of attribute datapoints.
3 4 5 |
# File 'lib/data_set.rb', line 3 def datapoints @datapoints end |
#max_date ⇒ Object (readonly)
Returns the value of attribute max_date.
4 5 6 |
# File 'lib/data_set.rb', line 4 def max_date @max_date end |
#max_value ⇒ Object (readonly)
Returns the value of attribute max_value.
4 5 6 |
# File 'lib/data_set.rb', line 4 def max_value @max_value end |
#min_date ⇒ Object (readonly)
Returns the value of attribute min_date.
4 5 6 |
# File 'lib/data_set.rb', line 4 def min_date @min_date end |
#min_value ⇒ Object (readonly)
Returns the value of attribute min_value.
4 5 6 |
# File 'lib/data_set.rb', line 4 def min_value @min_value end |
Instance Method Details
#dates ⇒ Object
37 38 39 |
# File 'lib/data_set.rb', line 37 def dates @datapoints.collect{|point| point[0]} end |
#value_for_date(date) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/data_set.rb', line 45 def value_for_date(date) begin return @datapoints.detect{|point| point[0]==date}[1] rescue raise "That date is not in the dataset." end end |
#values ⇒ Object
41 42 43 |
# File 'lib/data_set.rb', line 41 def values @datapoints.collect{|point| point[1]} end |
#values_for_google_chart ⇒ Object
17 18 19 |
# File 'lib/data_set.rb', line 17 def values_for_google_chart values.join(',') end |