Class: PeriodicCalculations::QueryOptions

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

Constant Summary collapse

OPERATION =
[:count, :max, :min, :sum, :avg]
INTERVAL_UNIT =
[:day, :week, :month, :year]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, column_name, window_start, window_end, options = {}) ⇒ QueryOptions

Returns a new instance of QueryOptions.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/periodic_calculations/query_options.rb', line 15

def initialize(operation, column_name, window_start, window_end, options = {})
  @operation = operation
  @target_column = column_name
  @timestamp_column = options[:timestamp_column] || :created_at
  @window_start = window_start
  @window_end = window_end
  @interval_unit = options[:interval_unit] || :day
  @cumulative = !!options[:cumulative]
  @timezone_offset = Time.now.in_time_zone.utc_offset

  validate!
end

Instance Attribute Details

#cumulativeObject (readonly)

Returns the value of attribute cumulative.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def cumulative
  @cumulative
end

#interval_unitObject (readonly)

Returns the value of attribute interval_unit.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def interval_unit
  @interval_unit
end

#operationObject (readonly)

Returns the value of attribute operation.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def operation
  @operation
end

#target_columnObject (readonly)

Returns the value of attribute target_column.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def target_column
  @target_column
end

#timestamp_columnObject (readonly)

Returns the value of attribute timestamp_column.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def timestamp_column
  @timestamp_column
end

#timezone_offsetObject (readonly)

Returns the value of attribute timezone_offset.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def timezone_offset
  @timezone_offset
end

#window_endObject (readonly)

Returns the value of attribute window_end.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def window_end
  @window_end
end

#window_startObject (readonly)

Returns the value of attribute window_start.



6
7
8
# File 'lib/periodic_calculations/query_options.rb', line 6

def window_start
  @window_start
end