Class: KPI::Report

Inherits:
Object
  • Object
show all
Extended by:
Memoizable, SuppressMemoization
Includes:
DynamicDefinitions
Defined in:
app/models/kpi/report.rb,
app/models/kpi/report/dynamic_definitions.rb,
app/models/kpi/report/suppress_memoization.rb

Defined Under Namespace

Modules: DynamicDefinitions, SuppressMemoization

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SuppressMemoization

suppress_memoization, suppressed_memoization?

Methods included from Memoizable

memoize, memoized_ivar_for

Methods included from DynamicDefinitions

included

Constructor Details

#initialize(*args) ⇒ Report

Returns a new instance of Report.



10
11
12
13
14
# File 'app/models/kpi/report.rb', line 10

def initialize(*args)
  @options = args.extract_options!
  @time = @options[:time] || Time.now
  @title = @options[:title] || self.class.name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



38
39
40
41
42
# File 'app/models/kpi/report.rb', line 38

def method_missing(name, *args)
  # check if KPI exists in report if name of missing method has trailing '?'
  return kpi_exists?($1.to_sym) if (/(.*)\?/ =~ name.to_s)
  super
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



15
16
17
# File 'app/models/kpi/report.rb', line 15

def time
  @time
end

#titleObject (readonly)

Returns the value of attribute title.



15
16
17
# File 'app/models/kpi/report.rb', line 15

def title
  @title
end

Instance Method Details

#collect!Object



17
18
19
20
# File 'app/models/kpi/report.rb', line 17

def collect!
  self.defined_kpis.each {|kpi_method| send(kpi_method) }
  self
end

#defined_kpisObject



30
31
32
# File 'app/models/kpi/report.rb', line 30

def defined_kpis
  self.class.defined_kpis.map(&:to_sym)
end

#entriesObject



22
23
24
25
26
27
28
# File 'app/models/kpi/report.rb', line 22

def entries
  Enumerator.new do |yielder|
    self.class.defined_kpis.each do |kpi_method|
      yielder.yield(send(kpi_method))
    end
  end
end

#result(*args) ⇒ Object



34
35
36
# File 'app/models/kpi/report.rb', line 34

def result(*args)
  KPI::Entry.new *args
end