Class: Wonkavision::Analytics::MemberFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/wonkavision/plugins/analytics/member_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member_name, options = {}) ⇒ MemberFilter

Returns a new instance of MemberFilter.



8
9
10
11
12
13
14
15
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 8

def initialize(member_name, options={})
  @name = member_name
  @attribute_name = options[:attribute_name]
  @operator = options[:operator] || options[:op] || :eq
  @member_type = options[:member_type] || :dimension
  @value = options[:value]
  @applied = false
end

Instance Attribute Details

#member_typeObject (readonly)

Returns the value of attribute member_type.



5
6
7
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 5

def member_type
  @member_type
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 5

def name
  @name
end

#operatorObject (readonly)

Returns the value of attribute operator.



5
6
7
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 5

def operator
  @operator
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 6

def value
  @value
end

Instance Method Details

#applied!Object



29
30
31
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 29

def applied!
  @applied = true
end

#applied?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 33

def applied?
  @applied
end

#attribute_key(aggregation) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 66

def attribute_key(aggregation)
  attribute_key = attribute_name.to_s
  #If the attribute name is key, caption or sort, we need to find the real name of the underling
  # attribute
  if dimension?
    dimension = aggregation.dimensions[name]
    raise "Error applying a member filter: Dimension #{name} does not exist" unless dimension
    attribute_key = dimension.send(attribute_name).to_s if dimension.respond_to?(attribute_name)
  end
  attribute_key
end

#attribute_nameObject



17
18
19
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 17

def attribute_name
  @attribute_name ||= dimension? ? :key : :count
end

#dimension?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 21

def dimension?
  member_type == :dimension
end

#matches(aggregation, tuple) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 44

def matches(aggregation, tuple)
  #this check allows the database adapter to apply a filter at the db query level
  #Wonkavision will avoid the overhead of checking again if the store signals it has taken care of things
  return true if @applied || tuple.blank?

  assert_operator_matches_value

  data = extract_attribute_value_from_tuple(aggregation, tuple)

  case operator
  when :gt then data ? data > value : false
  when :lt then data ? data < value : false
  when :gte then data ? data >= value : false
  when :lte then data ? data <= value : false
  when :in then value.include?(data)
  when :nin then !value.include?(data)
  when :ne then data != value
  when :eq then value == data
  else raise "Unknown filter operator #{operator}"
  end
end

#measure?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 25

def measure?
  member_type == :measure
end