Class: SpotFeel::Interval

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

Overview

  1. interval = ( open interval start | closed interval start ) , endpoint , “..” , endpoint , ( open interval end | closed interval end ) ;

Instance Method Summary collapse

Methods inherited from Node

#qualified_names_in_context, #raise_evaluation_error

Instance Method Details

#eval(context = {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/spot_feel/nodes.rb', line 110

def eval(context = {})
  start = start_token.text_value
  finish = end_token.text_value
  first_val = first.eval(context)
  second_val = second.eval(context)

  case [start, finish]
  when ['(', ')']
    ->(input) { first_val < input && input < second_val }
  when ['[', ']']
    ->(input) { first_val <= input && input <= second_val }
  when ['(', ']']
    ->(input) { first_val < input && input <= second_val }
  when ['[', ')']
    ->(input) { first_val <= input && input < second_val }
  end
end