Class: Casino::Intersection::Match::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/casino/intersection/match/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, key, selector, value = nil) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/casino/intersection/match/base.rb', line 7

def initialize(document, key, selector, value = nil)
  self.document = document
  self.field    = selector[key]
  self.key      = key
  self.selector = selector
  self.value    = document_value || value
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/casino/intersection/match/base.rb', line 5

def document
  @document
end

#fieldObject

Returns the value of attribute field.



5
6
7
# File 'lib/casino/intersection/match/base.rb', line 5

def field
  @field
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/casino/intersection/match/base.rb', line 5

def key
  @key
end

#selectorObject

Returns the value of attribute selector.



5
6
7
# File 'lib/casino/intersection/match/base.rb', line 5

def selector
  @selector
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/casino/intersection/match/base.rb', line 5

def value
  @value
end

Instance Method Details

#evaluateObject



15
16
17
# File 'lib/casino/intersection/match/base.rb', line 15

def evaluate
  matcher.evaluate
end

#match_argumentsObject



19
20
21
# File 'lib/casino/intersection/match/base.rb', line 19

def match_arguments
  [ key, value, document, field ]
end

#matcherObject



27
28
29
# File 'lib/casino/intersection/match/base.rb', line 27

def matcher
  matchers.find { |matcher| matcher.eligible? }
end

#matcher_for(class_name) ⇒ Object



31
32
33
34
# File 'lib/casino/intersection/match/base.rb', line 31

def matcher_for(class_name)
  class_name = String(class_name).humanize
  Match.const_get(class_name).new(*match_arguments)
end

#matchersObject



23
24
25
# File 'lib/casino/intersection/match/base.rb', line 23

def matchers
  matcher_classes.map { |class_name| matcher_for class_name }
end