Sha256: c31dd655ac48c9dfa25a6da3c637bfffe57b6459427767588646163e61bf91dd

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Grumlin
  module Expressions
    class 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
        %i[eq gt lt neq].each do |predicate|
          define_method predicate do |*args|
            Predicate.new("P", predicate, value: args[0])
          end
        end

        %i[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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
grumlin-0.23.0 lib/grumlin/expressions/p.rb
grumlin-0.22.5 lib/grumlin/expressions/p.rb
grumlin-0.22.4 lib/grumlin/expressions/p.rb
grumlin-0.22.3 lib/grumlin/expressions/p.rb
grumlin-0.22.2 lib/grumlin/expressions/p.rb
grumlin-0.22.1 lib/grumlin/expressions/p.rb
grumlin-0.22.0 lib/grumlin/expressions/p.rb
grumlin-0.21.1 lib/grumlin/expressions/p.rb
grumlin-0.21.0 lib/grumlin/expressions/p.rb
grumlin-0.20.2 lib/grumlin/expressions/p.rb
grumlin-0.20.1 lib/grumlin/expressions/p.rb
grumlin-0.20.0 lib/grumlin/expressions/p.rb
grumlin-0.19.7 lib/grumlin/expressions/p.rb