class MarkMapper::Normalizers::CriteriaHashValue
Constants
- NestingOperators
Internal: Used by normalized_value to determine if we need to run the value through another criteria hash to normalize it.
Public Class Methods
new(criteria_hash)
click to toggle source
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 9 def initialize(criteria_hash) @criteria_hash = criteria_hash end
Public Instance Methods
call(parent_key, key, value)
click to toggle source
Public: Returns value normalized for MarkLogic
parent_key - The parent key if nested, otherwise same as key key - The key we are currently normalizing value - The value that should be normalized
Returns value normalized for MarkLogic
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 20 def call(parent_key, key, value) case value when Array, Set if nesting_operator?(key) value.map { |v| criteria_hash_class.new(v, options).to_hash } elsif parent_key == key && !modifier?(key) && !value.empty? # we're not nested and not the value for a symbol operator {:$eq => value.to_a} else # we are a value for a symbol operator or nested hash value.to_a end when Time value.utc when String value when Hash value.each { |k, v| value[k] = call(key, k, v) } value when Regexp Regexp.new(value) else value end end
criteria_hash_class()
click to toggle source
Private: Returns class of provided criteria hash
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 47 def criteria_hash_class @criteria_hash.class end
modifier?(key)
click to toggle source
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 61 def modifier?(key) MarkMapper.modifier?(key) end
nesting_operator?(key)
click to toggle source
Private: Returns true or false if key is a nesting operator
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 57 def nesting_operator?(key) NestingOperators.include?(key) end
options()
click to toggle source
Private: Returns options of provided criteria hash
# File lib/mark_mapper/normalizers/criteria_hash_value.rb, line 52 def options @criteria_hash.options end