class PIM::Statistics::StatisticsBuilder

Public Class Methods

new(statistics, statistic_templates, &block) click to toggle source
# File statistics.rb, line 197
def initialize statistics, statistic_templates, &block
  @statistics = statistics
  @statistic_templates = statistic_templates
  self.instance_exec(&block)
end

Public Instance Methods

statistic(name, &block) click to toggle source
# File statistics.rb, line 203
def statistic name, &block
  name = name.to_s
  if block
    raise "Statistic '#{name}' is already defined" if @statistics.include?(name)
    statistic = Statistic.new(name, &block)
    @statistics[statistic.name] = statistic
  else
    statistic = @statistics[name]
  end
  statistic
end
statistic_from_template(name, template_name = name, params = {}) click to toggle source
# File statistics.rb, line 227
def statistic_from_template name, template_name = name, params = {}
  statistic_template = @statistic_templates[template_name]
  raise "Statistic template '#{template_name}' does not exist" if statistic_template.nil?
  raise "Statistic '#{name}' is already defined" if @statistics.include?(name)
  statistic = statistic_template.create_statistic(name, params)
  @statistics[statistic.name] = statistic
  statistic
end
statistic_template(name, &block) click to toggle source
# File statistics.rb, line 215
def statistic_template name, &block
  name = name.to_s
  if block
    raise "Statistic template '#{name}' is already defined" if @statistic_templates.include?(name)
    statistic_template = StatisticTemplate.new(name, &block)
    @statistic_templates[statistic_template.name] = statistic_template
  else
    statistic_template = @statistic_templates[name]
  end
  statistic_template
end
statistic_with_template(name, template_name = name, params = {}) click to toggle source
# File statistics.rb, line 236
def statistic_with_template name, template_name = name, params = {}, &block
  statistic_template = statistic_template(template_name, &block)
  statistic = statistic_from_template(name, template_name, params)
  statistic
end