Class: DataSet

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

Defined Under Namespace

Classes: DailyDataSet, DayOfWeekDataSet, HourOfDayDataSet, HourlyDataSet, MonthlyDataSet

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/data_set.rb', line 4

def count
  @count
end

#datapointsObject

Returns the value of attribute datapoints.



3
4
5
# File 'lib/data_set.rb', line 3

def datapoints
  @datapoints
end

#max_dateObject (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_valueObject (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_dateObject (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_valueObject (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

#datesObject



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

#valuesObject



41
42
43
# File 'lib/data_set.rb', line 41

def values
  @datapoints.collect{|point| point[1]}
end

#values_for_google_chartObject



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

def values_for_google_chart
  values.join(',')
end