Class: Wonkavision::Analytics::MemberFilter
- Inherits:
-
Object
- Object
- Wonkavision::Analytics::MemberFilter
- Defined in:
- lib/wonkavision/plugins/analytics/member_filter.rb
Instance Attribute Summary collapse
-
#member_type ⇒ Object
readonly
Returns the value of attribute member_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #applied! ⇒ Object
- #applied? ⇒ Boolean
- #attribute_key(aggregation) ⇒ Object
- #attribute_name ⇒ Object
- #dimension? ⇒ Boolean
-
#initialize(member_name, options = {}) ⇒ MemberFilter
constructor
A new instance of MemberFilter.
- #matches(aggregation, tuple) ⇒ Object
- #measure? ⇒ Boolean
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, ={}) @name = member_name @attribute_name = [:attribute_name] @operator = [:operator] || [:op] || :eq @member_type = [:member_type] || :dimension @value = [:value] @applied = false end |
Instance Attribute Details
#member_type ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 5 def name @name end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
5 6 7 |
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 5 def operator @operator end |
#value ⇒ Object
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
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_name ⇒ Object
17 18 19 |
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 17 def attribute_name @attribute_name ||= dimension? ? :key : :count end |
#dimension? ⇒ 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
25 26 27 |
# File 'lib/wonkavision/plugins/analytics/member_filter.rb', line 25 def measure? member_type == :measure end |