Class: SplitIoClient::BetweenMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/engine/matchers/between_matcher.rb

Constant Summary collapse

MATCHER_TYPE =
'BETWEEN'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_hash) ⇒ BetweenMatcher

Returns a new instance of BetweenMatcher.



7
8
9
10
11
12
# File 'lib/splitclient-rb/engine/matchers/between_matcher.rb', line 7

def initialize(attribute_hash)
  @attribute = attribute_hash[:attribute]
  @data_type = attribute_hash[:data_type]
  @start_value = formatted_value(attribute_hash[:start_value], true)
  @end_value = formatted_value(attribute_hash[:end_value], true)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/splitclient-rb/engine/matchers/between_matcher.rb', line 5

def attribute
  @attribute
end

Instance Method Details

#equals?(obj) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/splitclient-rb/engine/matchers/between_matcher.rb', line 25

def equals?(obj)
  if obj.nil?
    false
  elsif !obj.instance_of?(BetweenMatcher)
    false
  elsif self.equal?(obj)
    true
  else
    false
  end
end

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/splitclient-rb/engine/matchers/between_matcher.rb', line 14

def match?(args)
  return false if !args.key?(:attributes) && !args.key?(:value)
  return false if args.key?(:value) && args[:value].nil?
  return false if args.key?(:attributes) && args[:attributes].nil?

  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])
  return false unless value.is_a?(Integer)

  (@start_value..@end_value).include? value
end

#string_type?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/splitclient-rb/engine/matchers/between_matcher.rb', line 37

def string_type?
  false
end