Class: Dashboards::ChangeOverPeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/dashboards/dsl/change_over_period.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_or_options, options = {}) ⇒ ChangeOverPeriod

Returns a new instance of ChangeOverPeriod.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dashboards/dsl/change_over_period.rb', line 7

def initialize(data_or_options, options = {})
  if data_or_options.is_a?(Hash)
    @data = data_or_options[:data]
    @options = data_or_options.except(:data)
  else
    @data = data_or_options
    @options = options
  end
  @period = @options[:period] || 7.days
  @date_column = @options[:date_column] || :created_at
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/dashboards/dsl/change_over_period.rb', line 5

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/dashboards/dsl/change_over_period.rb', line 5

def options
  @options
end

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
# File 'lib/dashboards/dsl/change_over_period.rb', line 19

def render(context)
  data = @data.is_a?(Proc) ? context.instance_exec(&@data) : @data
  render_change(data, context)
end