Module: Tabloid::Report::InstanceMethods

Defined in:
lib/tabloid/report.rb

Instance Method Summary collapse

Instance Method Details

#cache_keyObject



117
118
119
120
121
122
123
124
125
# File 'lib/tabloid/report.rb', line 117

def cache_key
  @key ||= begin
    if self.class.cache_key_block
      self.instance_exec &self.class.cache_key_block
    else
      nil
    end
  end
end

#dataObject



103
104
105
106
107
# File 'lib/tabloid/report.rb', line 103

def data
  load_from_cache if Tabloid.cache_enabled?
  build_and_cache_data
  @data
end

#parameter(key) ⇒ Object



98
99
100
101
# File 'lib/tabloid/report.rb', line 98

def parameter(key)
  load_from_cache if Tabloid.cache_enabled?
  @report_parameters[key] if @report_parameters
end

#parametersObject



94
95
96
# File 'lib/tabloid/report.rb', line 94

def parameters
  self.class.parameters
end

#prepare(options = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tabloid/report.rb', line 76

def prepare(options={})
  before_prepare if self.respond_to?(:before_prepare)
  @report_parameters = {}
  parameters.each do |param|
    value = options.delete param.key
    raise Tabloid::MissingParameterError.new("Must supply :#{param.key} when creating the report") unless value
    @report_parameters[param.key] = value
  end
  data
  after_prepare if self.respond_to?(:after_prepare)

  self
end

#report_columnsObject



90
91
92
# File 'lib/tabloid/report.rb', line 90

def report_columns
  self.class.report_columns
end

#to_csvObject



113
114
115
# File 'lib/tabloid/report.rb', line 113

def to_csv
  data.to_csv
end

#to_htmlObject



109
110
111
# File 'lib/tabloid/report.rb', line 109

def to_html
  "<table>#{data.to_html}</table>"
end