Class: SpotFeel::InstanceOf

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

Overview

  1. instance of = expression , “instance” , “of” , type ;

Instance Method Summary collapse

Methods inherited from Node

#qualified_names_in_context, #raise_evaluation_error

Instance Method Details

#eval(context = {}) ⇒ Object



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/spot_feel/nodes.rb', line 525

def eval(context = {})
  case type.text_value
  when "string"
    ->(input) { input.is_a?(String) }
  when "number"
    ->(input) { input.is_a?(Numeric) }
  when "boolean"
    ->(input) { input.is_a?(TrueClass) || input.is_a?(FalseClass) }
  when "date"
    ->(input) { input.is_a?(Date) }
  when "time"
    ->(input) { input.is_a?(Time) }
  when "date and time"
    ->(input) { input.is_a?(DateTime) }
  when "duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) }
  when "years and months duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:months, :years] }
  when "days and time duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:days, :hours, :minutes, :seconds] }
  when "years duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:years] }
  when "months duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:months] }
  when "days duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:days] }
  when "hours duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:hours] }
  when "minutes duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:minutes] }
  when "seconds duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:seconds] }
  when "time duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:hours, :minutes, :seconds] }
  when "years and months duration"
    ->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:months, :years] }
  when "list"
    ->(input) { input.is_a?(Array) }
  when "interval"
    ->(input) { input.is_a?(Range) }
  when "context"
    ->(input) { input.is_a?(Hash) }
  when "any"
    ->(_input) { true }
  end
end