Class: CohortAnalysis::Strategy::Strict

Inherits:
CohortAnalysis::Strategy show all
Defined in:
lib/cohort_analysis/strategy/strict.rb

Constant Summary

Constants inherited from CohortAnalysis::Strategy

DEFAULT_STRATEGY

Instance Attribute Summary collapse

Attributes inherited from CohortAnalysis::Strategy

#current, #minimum_size, #original, #select_manager, #table, #table_name

Instance Method Summary collapse

Methods inherited from CohortAnalysis::Strategy

#==, create, #expr, #final

Constructor Details

#initialize(select_manager, characteristics, options = {}) ⇒ Strict

Returns a new instance of Strict.



6
7
8
9
10
11
12
13
# File 'lib/cohort_analysis/strategy/strict.rb', line 6

def initialize(select_manager, characteristics, options = {})
  super
  if priority = options[:priority]
    @reverse_priority = priority.reverse
  elsif ::RUBY_VERSION < '1.9' and not characteristics.is_a?(::ActiveSupport::OrderedHash)
    raise ::ArgumentError, "[cohort_analysis] Since Ruby 1.8 hashes are not ordered, please use :priority => [...] or pass characteristics as an ActiveSupport::OrderedHash (not recommended)"
  end
end

Instance Attribute Details

#reverse_priorityObject (readonly)

Returns the value of attribute reverse_priority.



4
5
6
# File 'lib/cohort_analysis/strategy/strict.rb', line 4

def reverse_priority
  @reverse_priority
end

Instance Method Details

#reduce!Object

Reduce characteristics by removing the least important one.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cohort_analysis/strategy/strict.rb', line 16

def reduce!
  least_important_key = if reverse_priority
    reverse_priority.detect do |k|
      current.has_key? k
    end
  else
    current.keys.last
  end
  if least_important_key
    current.delete least_important_key
  else
    raise ::RuntimeError, "[cohort_analysis] Priority improperly specified"
  end
end