Class: FEEL::SimplePositiveUnaryTest

Inherits:
Node
  • Object
show all
Defined in:
lib/feel/nodes.rb

Overview

  1. simple positive unary test =

7.a [ “<” | “<=” | “>” | “>=” ] , endpoint | 7.b interval ;

Instance Method Summary collapse

Methods inherited from Node

#access_property, #contains_input_placeholder?, #qualified_names_in_context, #raise_evaluation_error

Instance Method Details

#eval(context = {}) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/feel/nodes.rb', line 133

def eval(context = {})
  operator = head.text_value.strip

  if operator.empty? && tail.respond_to?(:contains_input_placeholder?) && tail.contains_input_placeholder?
    return ->(input) { tail.eval(context.merge("?" => input)) }
  end

  endpoint = tail.eval(context)

  case operator
  when "<"
    ->(input) { input.nil? || endpoint.nil? ? nil : input < endpoint }
  when "<="
    ->(input) { input.nil? || endpoint.nil? ? nil : input <= endpoint }
  when ">"
    ->(input) { input.nil? || endpoint.nil? ? nil : input > endpoint }
  when ">="
    ->(input) { input.nil? || endpoint.nil? ? nil : input >= endpoint }
  else
    ->(input) { input == endpoint }
  end
end