Class: DataSet::DailyDataSet
- Defined in:
- lib/data_set/daily_data_set.rb
Instance Attribute Summary
Attributes inherited from DataSet
#count, #datapoints, #max_date, #max_value, #min_date, #min_value
Instance Method Summary collapse
-
#date_labels ⇒ Object
Array of dates in “Nov 18” format corresponding to datapoints at one week increments working backwords from today.
-
#dates ⇒ Object
Array of dates corresponding to datapoints in “2009-11-18” format.
- #full_weeks_in_dataset ⇒ Object
-
#initialize(point_array, count = 30) ⇒ DailyDataSet
constructor
A new instance of DailyDataSet.
-
#month_labels ⇒ Object
Array containing month names corresponding to datapoint positions which represent the first day of the month.
Methods inherited from DataSet
#value_for_date, #values, #values_for_google_chart
Constructor Details
#initialize(point_array, count = 30) ⇒ DailyDataSet
Returns a new instance of DailyDataSet.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/data_set/daily_data_set.rb', line 3 def initialize( point_array, count = 30 ) @datapoints ||= {} #[["2008-06-01", 200.58], ["2008-06-02", 205.39]] @count = count point_array.each do |date, value| value = value.to_f @datapoints[date.to_s] = value end fill_with_zeroes(@count) end |
Instance Method Details
#date_labels ⇒ Object
Array of dates in “Nov 18” format corresponding to datapoints at one week increments working backwords from today. Compare today’s DOW (“Mon”) to each date in the array, and only return “Nov 18” for dates that match the DOW.
24 25 26 27 28 29 30 |
# File 'lib/data_set/daily_data_set.rb', line 24 def date_labels if @count < 90 dates.collect { |date| date.to_date.strftime('%d') == Time.now.strftime('%a') ? date.to_date.strftime("%b %e") : '' } else dates.collect { |date| date.to_date.strftime('%d') == '01' ? date.to_date.strftime("%b %e") : '' } end end |
#dates ⇒ Object
Array of dates corresponding to datapoints in “2009-11-18” format
17 18 19 |
# File 'lib/data_set/daily_data_set.rb', line 17 def dates @datapoints.collect{|point| point[0]} end |
#full_weeks_in_dataset ⇒ Object
32 33 34 |
# File 'lib/data_set/daily_data_set.rb', line 32 def full_weeks_in_dataset @count.to_i / 7 end |
#month_labels ⇒ Object
Array containing month names corresponding to datapoint positions which represent the first day of the month.
- ”,”,‘December’,”,”
38 39 40 |
# File 'lib/data_set/daily_data_set.rb', line 38 def month_labels dates.collect{|date| date.to_date.day==1 ? date.to_date.strftime("%B") : ''} end |