Class: C2::Reporter::Report

Inherits:
Object
  • Object
show all
Defined in:
app/models/c2/reporter/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass_name, options = {}, &block) ⇒ Report

Returns a new instance of Report.



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/c2/reporter/report.rb', line 11

def initialize(klass_name, options={}, &block)
  @options = options.with_indifferent_access

  @buckets = []
  @klass_name = klass_name
  @meta = @options.delete(:meta)

  instance_eval(&block)

  ::C2::Reporter.reports.push(self)
end

Instance Attribute Details

#bucketsObject

Returns the value of attribute buckets.



7
8
9
# File 'app/models/c2/reporter/report.rb', line 7

def buckets
  @buckets
end

#metaObject

Returns the value of attribute meta.



9
10
11
# File 'app/models/c2/reporter/report.rb', line 9

def meta
  @meta
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'app/models/c2/reporter/report.rb', line 8

def options
  @options
end

#refreshed_atObject

Returns the value of attribute refreshed_at.



6
7
8
# File 'app/models/c2/reporter/report.rb', line 6

def refreshed_at
  @refreshed_at
end

Instance Method Details

#as_json(options = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'app/models/c2/reporter/report.rb', line 40

def as_json(options={})
  {
    :id => self.id,
    :label => self.label,
    :buckets => self.buckets
  }
end

#idObject



27
28
29
# File 'app/models/c2/reporter/report.rb', line 27

def id
  @klass_name.to_sym
end

#klassObject



23
24
25
# File 'app/models/c2/reporter/report.rb', line 23

def klass
  @klass_cache ||= @klass_name.to_s.classify.constantize
end

#labelObject



31
32
33
# File 'app/models/c2/reporter/report.rb', line 31

def label
  @klass_name.to_s.pluralize.titleize
end

#refreshObject



35
36
37
38
# File 'app/models/c2/reporter/report.rb', line 35

def refresh
  @buckets.each(&:refresh)
  @refreshed_at = Time.now.utc
end