lib/revector.rb in revector-0.1.0 vs lib/revector.rb in revector-0.1.1
- old
+ new
@@ -1,13 +1,14 @@
# frozen_string_literal: true
require 'set'
require_relative 'revector/utility'
+require_relative 'revector/predicate/equal'
+require_relative 'revector/predicate/exists'
require_relative 'revector/predicate/startify'
require_relative 'revector/predicate/endify'
-require_relative 'revector/predicate/equal'
require_relative 'revector/predicate/contains'
require_relative 'revector/predicate/in'
require_relative 'revector/predicate/less_than'
require_relative 'revector/predicate/greater_than'
@@ -52,10 +53,11 @@
predicatable = Predicate[predicate]
valueable = value.respond_to?(:call) ? value.call : value
case right
in [*]
+ right = [''] unless right.any?
Array(right).any? { |o| predicatable.compare(o, valueable) }
else
predicatable.compare(right, valueable)
end
end
@@ -65,11 +67,11 @@
parts = key.to_s.split('_')
predicate = Array(parts[-2..]).filter do |pkey|
next unless PREDICATES.include? pkey
- parts = parts - [pkey]
+ parts -= [pkey]
pkey
end&.last || :eq
iteratee = parts.join('_')
@@ -101,24 +103,28 @@
end: Endify,
notend: NotEndify,
not_end: NotEndify,
in: Included,
notin: NotIncluded,
- not_in: NotIncluded
+ not_in: NotIncluded,
+ ex: Exists,
+ not_ex: NotExists
}[named.to_sym || :eq]
end
private_constant :Predicate
AFFIRMATIVES = %w[
- eq
+ eq ex
in cont
lt lteq
gt gteq
- st start end
+ st start
+ end
].freeze
NEGATIVES = %w[
noteq not_eq
+ not_ex
notcont not_cont
notstart notst not_start not_st
notend not_end
notin not_in
].freeze