Class: QueryReport::ChartAdapterModule::ChartAdapter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, records, chart_type, chart_title) ⇒ ChartAdapter

Returns a new instance of ChartAdapter.



20
21
22
23
24
25
26
# File 'lib/query_report/chart_adapter.rb', line 20

def initialize(query, records, chart_type, chart_title)
  @query = query
  @records = records
  @chart_type = chart_type
  @chart = "Chartify::#{chart_type.to_s.camelize}Chart".constantize.new
  @chart.title = chart_title
end

Instance Attribute Details

#chartObject

Returns the value of attribute chart.



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

def chart
  @chart
end

#chart_typeObject

Returns the value of attribute chart_type.



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

def chart_type
  @chart_type
end

#queryObject (readonly)

Returns the value of attribute query.



16
17
18
# File 'lib/query_report/chart_adapter.rb', line 16

def query
  @query
end

#recordsObject (readonly)

Returns the value of attribute records.



16
17
18
# File 'lib/query_report/chart_adapter.rb', line 16

def records
  @records
end

Instance Method Details

#sum_with(options) ⇒ Object



28
29
30
31
32
33
# File 'lib/query_report/chart_adapter.rb', line 28

def sum_with(options)
  @chart.data = []
  options.each do |column_title, column|
    @chart.data << [column_title, query.sum(column)]
  end
end