Class: DataSet::MonthlyDataSet

Inherits:
DataSet
  • Object
show all
Defined in:
lib/data_set/monthly_data_set.rb

Instance Attribute Summary

Attributes inherited from DataSet

#count, #datapoints, #max_date, #max_value, #min_date, #min_value

Instance Method Summary collapse

Methods inherited from DataSet

#dates, #value_for_date, #values, #values_for_google_chart

Constructor Details

#initialize(point_array, count = 24) ⇒ MonthlyDataSet

Returns a new instance of MonthlyDataSet.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/data_set/monthly_data_set.rb', line 3

def initialize( point_array, count = 24 )

  @datapoints ||= {} #[["2008-06", 200.58], ["2008-07", 205.39]]
  @count = count
  
  point_array.each do |date, value|
    value = value.to_f
    @datapoints[date] = value
  end
  fill_with_zeroes(@count)
  truncate_datapoints
end

Instance Method Details

#month_labelsObject

Array of abbreviated months (‘Jan’, ‘Feb’) corresponding to datapoints



22
23
24
25
26
# File 'lib/data_set/monthly_data_set.rb', line 22

def month_labels
  months.collect{ |month| 
    "#{month}-01".to_date.strftime("%b")
  }
end

#monthsObject

Return array of months in ‘2009-11’ format corresponding to datapoints



17
18
19
# File 'lib/data_set/monthly_data_set.rb', line 17

def months
  @datapoints.collect{ |point| point[0] }
end

#year_labelsObject

Array containing full year (2009) x-axis labels stacked beneath month labels that are “Jan”



29
30
31
# File 'lib/data_set/monthly_data_set.rb', line 29

def year_labels
  months.collect{|month| "#{month}-01".to_date.month==1 ? "#{month}-01".to_date.year : '' }
end