Class: ReportMe::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Report

Returns a new instance of Report.



8
9
10
# File 'lib/report_me/report.rb', line 8

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/report_me/report.rb', line 6

def name
  @name
end

Instance Method Details

#source(&block) ⇒ Object



12
13
14
# File 'lib/report_me/report.rb', line 12

def source(&block)
  @source = block
end

#sql(von, bis) ⇒ Object



16
17
18
# File 'lib/report_me/report.rb', line 16

def sql(von, bis)
  @source.call(von, bis)
end

#table_exist?(period) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/report_me/report.rb', line 24

def table_exist?(period)
  ActiveRecord::Base.connection.select_value("show tables like '#{table_name(period)}'") != nil
end

#table_name(period) ⇒ Object



20
21
22
# File 'lib/report_me/report.rb', line 20

def table_name(period)
  "#{name}_#{period}"
end