Class: Dashboards::Summary

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

Constant Summary collapse

DEFAULT_PERIODS =
[
  { name: '24h', duration: 24.hours },
  { name: '7d', duration: 7.days },
  { name: '30d', duration: 30.days }
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Summary.



13
14
15
16
17
18
19
20
21
22
# File 'lib/dashboards/dsl/summary.rb', line 13

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
  @periods = @options[:periods] || DEFAULT_PERIODS
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#render(context) ⇒ Object



24
25
26
27
# File 'lib/dashboards/dsl/summary.rb', line 24

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