Class: MixpanelMagicLamp::InstanceMethods::ExpressionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mixpanel_magic_lamp/expression_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ExpressionBuilder

Returns a new instance of ExpressionBuilder.



17
18
19
20
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 17

def initialize(*args)
  @expression = ''
  equals(*args) if args.any?
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



15
16
17
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 15

def expression
  @expression
end

Instance Method Details

#andObject



26
27
28
29
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 26

def and
  @expression += ' and ' if @expression.present? and not @expression =~ /(and|or)\s*$/
  self
end

#contains(args = {}, union = 'and') ⇒ Object



46
47
48
49
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 46

def contains(args = {}, union = 'and')
  @expression += join(args, union, "\":value\" in (properties[\":name\"])")
  self
end

#does_not_contain(args = {}, union = 'and') ⇒ Object



51
52
53
54
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 51

def does_not_contain(args = {}, union = 'and')
  @expression += join(args, union, "not \":value\" in (properties[\":name\"])")
  self
end

#does_not_equal(args = {}, union = 'and') ⇒ Object



41
42
43
44
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 41

def does_not_equal(args = {}, union = 'and')
  @expression += join(args, union, "properties[\":name\"] != \":value\"")
  self
end

#equals(args = {}, union = 'and') ⇒ Object



36
37
38
39
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 36

def equals(args = {}, union = 'and')
  @expression += join(args, union, "properties[\":name\"] == \":value\"")
  self
end

#is_not_set(args = [], union = 'and') ⇒ Object



61
62
63
64
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 61

def is_not_set(args = [], union = 'and')
  @expression += join(args, union, "not defined (properties[\":name\"])")
  self
end

#is_set(args = [], union = 'and') ⇒ Object



56
57
58
59
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 56

def is_set(args = [], union = 'and')
  @expression += join(args, union, "defined (properties[\":name\"])")
  self
end

#orObject



31
32
33
34
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 31

def or
  @expression += ' or ' if @expression.present? and not @expression =~ /(and|or)\s*$/
  self
end

#to_sObject



22
23
24
# File 'lib/mixpanel_magic_lamp/expression_builder.rb', line 22

def to_s
  @expression
end