Module: MSFL::Validators::Definitions::HashKey

Included in:
Converters::Operator, Datasets::Base, Semantic
Defined in:
lib/msfl/validators/definitions/hash_key.rb

Instance Method Summary collapse

Instance Method Details

#all_logical_operators?(arr) ⇒ Bool

Returns true if all elements of arr are logical operators, false otherwise

Parameters:

  • arr (Array<Symbol>)

    and array of symbols to check to see if all elements are logical operators

Returns:

  • (Bool)

    it is true if all the elements are logical operators, otherwise false



80
81
82
83
84
85
# File 'lib/msfl/validators/definitions/hash_key.rb', line 80

def all_logical_operators?(arr)
  arr.each do |e|
    return false unless logical_operators.include?(e)
  end
  true
end

#all_operators?(arr) ⇒ Bool

Returns true if all elements of arr are operators, false otherwise

Parameters:

  • arr (Array<Symbol>)

    the Array of Symbols to be checked against the operators list

Returns:

  • (Bool)

    true if all of the elements of arr are operators



68
69
70
71
72
73
# File 'lib/msfl/validators/definitions/hash_key.rb', line 68

def all_operators?(arr)
  arr.each do |e|
    return false unless hash_key_operators.include?(e)
  end
  true
end

#any_operators?(arr) ⇒ Bool

Returns true if any of the elements in arr are operators, otherwise false

Parameters:

  • arr (Array)

    the array of elements to check for the presence of operators

Returns:

  • (Bool)

    true if any of the elements of arr are operators



91
92
93
94
95
96
# File 'lib/msfl/validators/definitions/hash_key.rb', line 91

def any_operators?(arr)
  arr.each do |e|
    return true if hash_key_operators.include?(e)
  end
  false
end

#binary_operatorsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/msfl/validators/definitions/hash_key.rb', line 19

def binary_operators
  [
      :in,          # IN
      :between,     # inclusive range for integers, dates, and date times
      :start,       # a range bound inclusively to the left
      :end,         # a range bound inclusively to the right
      :ellipsis2,   # alias to :between
      :tilda,       # alias to :between, :start, and :end depending on usage
      :eq,          # ==
      :lt,          # <
      :lte,         # <=
      :gt,          # >
      :gte,         # >=
      :neg,         # logical negation
  ]
end

#foreign_operatorsObject



44
45
46
47
48
49
50
# File 'lib/msfl/validators/definitions/hash_key.rb', line 44

def foreign_operators
  [
      :foreign,     # Defines a filter on a related item
      :dataset,     # A foreign dataset
      :filter,      # an explicit filter
  ]
end

#hash_key_operatorsObject

Operators still needing parsing: ellipsis2, tilda



15
16
17
# File 'lib/msfl/validators/definitions/hash_key.rb', line 15

def hash_key_operators
  binary_operators.concat(logical_operators).concat(partial_operators).concat(foreign_operators)
end

#logical_operatorsObject



52
53
54
# File 'lib/msfl/validators/definitions/hash_key.rb', line 52

def logical_operators
  [:and, :or]
end

#operator?(symbol) ⇒ Bool

Returns true if the argument is a valid operator

Parameters:

  • symbol (Symbol)

    the value to check to see if it is an operator

Returns:

  • (Bool)

    true if the argument is a valid operator, false otherwise



60
61
62
# File 'lib/msfl/validators/definitions/hash_key.rb', line 60

def operator?(symbol)
  hash_key_operators.include? symbol
end

#partial_operatorsObject



36
37
38
39
40
41
42
# File 'lib/msfl/validators/definitions/hash_key.rb', line 36

def partial_operators
  [
      :partial,     # faceted / aggregate
      :given,       # given
      :filter,      # explicit filter
  ]
end

#valid_hash_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/msfl/validators/definitions/hash_key.rb', line 6

def valid_hash_key?(key)
  self.dataset.has_operator?(key) || self.dataset.has_field?(key)
end

#valid_hash_keysObject



10
11
12
# File 'lib/msfl/validators/definitions/hash_key.rb', line 10

def valid_hash_keys
  hash_key_operators.concat self.dataset.fields
end