Module: Qrda::Export::Helper::PopulationSelectors

Included in:
PopulationGroup
Defined in:
lib/qrda-export/helper/aggregate_object_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 34

def method_missing(method, *args, &block)
  match_data = method.to_s.match(/^(.+)_count$/)
  if match_data
    population = send(match_data[1])
    if population
      population.value
    else
      0
    end
  else
    super
  end
end

Instance Method Details

#denominatorObject



9
10
11
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 9

def denominator
  populations.find { |pop| pop.type == 'DENOM' }
end

#denominator_exceptionsObject



13
14
15
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 13

def denominator_exceptions
  populations.find { |pop| pop.type == 'DENEXCEP' }
end

#denominator_exclusionsObject



17
18
19
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 17

def denominator_exclusions
  populations.find { |pop| pop.type == 'DENEX' }
end

#multiple_population_types?Boolean

Returns true if there is more than one IPP or DENOM, etc.

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 54

def multiple_population_types?
  population_groups = populations.group_by(&:type)
  population_groups.values.any? { |pops| pops.size > 1 }
end

#numeratorObject



5
6
7
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 5

def numerator
  populations.find { |pop| pop.type == 'NUMER' }
end

#population_count(population_type, population_id) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 21

def population_count(population_type, population_id)
  population = populations.find { |pop| pop.type == population_type && pop.id == population_id }
  if population
    population.value
  else
    0
  end
end

#population_id(population_type) ⇒ Object



30
31
32
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 30

def population_id(population_type)
  populations.find { |pop| pop.type == population_type }.id
end

#respond_to_missing?(method, *args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/qrda-export/helper/aggregate_object_helper.rb', line 48

def respond_to_missing?(method, *args)
  match_data = method.to_s.match(/^(.+)_count$/)
  !match_data.nil? or super
end