Sha256: 470d4d05e7bcf260ff3a3b8b635b0e8e57886bbf9d0000f54b7d3fb07b575a63

Contents?: true

Size: 915 Bytes

Versions: 15

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true

class Grumlin::Expressions::P
  class Predicate
    attr_reader :namespace, :name, :value, :type

    def initialize(namespace, name, value:, type: nil)
      @namespace = namespace
      @name = name
      @value = value
      @type = type
    end
  end

  class << self
    # TODO: support more predicates
    [:eq, :gt, :lt, :neq].each do |predicate|
      define_method predicate do |*args|
        Predicate.new("P", predicate, value: args[0])
      end
    end

    [:within, :without].each do |predicate|
      define_method predicate do |*args|
        args = if args.count == 1 && args[0].is_a?(Array)
                 args[0]
               elsif args.count == 1 && args[0].is_a?(Set)
                 args[0].to_a
               else
                 args.to_a
               end
        Predicate.new("P", predicate, value: args, type: "List")
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/expressions/p.rb
grumlin-1.1.0 lib/grumlin/expressions/p.rb
grumlin-1.0.4 lib/grumlin/expressions/p.rb
grumlin-1.0.3 lib/grumlin/expressions/p.rb
grumlin-1.0.3.beta1 lib/grumlin/expressions/p.rb
grumlin-1.0.2 lib/grumlin/expressions/p.rb
grumlin-1.0.1 lib/grumlin/expressions/p.rb
grumlin-1.0.0 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc7 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc6 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc5 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc4 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc3 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc2 lib/grumlin/expressions/p.rb
grumlin-1.0.0.rc1 lib/grumlin/expressions/p.rb