module Dry::Logic::Predicates::Methods

Public Instance Methods

[](name) click to toggle source
# File lib/dry/logic/predicates.rb, line 11
def [](name)
  method(name)
end
array?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 87
def array?(input)
  input.is_a?(Array)
end
attr?(name, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 28
def attr?(name, input)
  input.respond_to?(name)
end
bool?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 45
def bool?(input)
  input.is_a?(TrueClass) || input.is_a?(FalseClass)
end
bytesize?(size, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 132
def bytesize?(size, input)
  case size
  when Integer then size.equal?(input.bytesize)
  when Range, Array then size.include?(input.bytesize)
  else
    raise ArgumentError, "+#{size}+ is not supported type for bytesize? predicate."
  end
end
case?(pattern, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 205
def case?(pattern, input)
  pattern === input
end
date?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 49
def date?(input)
  input.is_a?(Date)
end
date_time?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 53
def date_time?(input)
  input.is_a?(DateTime)
end
decimal?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 75
def decimal?(input)
  input.is_a?(BigDecimal)
end
empty?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 32
def empty?(input)
  case input
  when String, Array, Hash then input.empty?
  when nil then true
  else
    false
  end
end
eql?(left, right) click to toggle source
# File lib/dry/logic/predicates.rb, line 181
def eql?(left, right)
  left.eql?(right)
end
even?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 95
def even?(input)
  input.even?
end
excluded_from?(list, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 163
def excluded_from?(list, input)
  !list.include?(input)
end
excludes?(value, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 177
def excludes?(value, input)
  !includes?(value, input)
end
exclusion?(list, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 154
def exclusion?(list, input)
  ::Kernel.warn "exclusion is deprecated - use excluded_from instead."
  excluded_from?(list, input)
end
false?(value) click to toggle source
# File lib/dry/logic/predicates.rb, line 197
def false?(value)
  value.equal?(false)
end
filled?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 41
def filled?(input)
  !empty?(input)
end
float?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 71
def float?(input)
  input.is_a?(Float)
end
format?(regex, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 201
def format?(regex, input)
  !input.nil? && regex.match?(input)
end
gt?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 103
def gt?(num, input)
  input > num
end
gteq?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 111
def gteq?(num, input)
  !lt?(num, input)
end
hash?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 83
def hash?(input)
  input.is_a?(Hash)
end
included_in?(list, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 159
def included_in?(list, input)
  list.include?(input)
end
includes?(value, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 167
def includes?(value, input)
  if input.respond_to?(:include?)
    input.include?(value)
  else
    false
  end
rescue TypeError
  false
end
inclusion?(list, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 149
def inclusion?(list, input)
  ::Kernel.warn "inclusion is deprecated - use included_in instead."
  included_in?(list, input)
end
int?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 67
def int?(input)
  input.is_a?(Integer)
end
is?(left, right) click to toggle source
# File lib/dry/logic/predicates.rb, line 185
def is?(left, right)
  left.equal?(right)
end
key?(name, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 24
def key?(name, input)
  input.key?(name)
end
lt?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 99
def lt?(num, input)
  input < num
end
lteq?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 107
def lteq?(num, input)
  !gt?(num, input)
end
max_bytesize?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 145
def max_bytesize?(num, input)
  input.bytesize <= num
end
max_size?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 128
def max_size?(num, input)
  input.size <= num
end
min_bytesize?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 141
def min_bytesize?(num, input)
  input.bytesize >= num
end
min_size?(num, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 124
def min_size?(num, input)
  input.size >= num
end
nil?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 19
def nil?(input)
  input.nil?
end
Also aliased as: none?
none?(input)
Alias for: nil?
not_eql?(left, right) click to toggle source
# File lib/dry/logic/predicates.rb, line 189
def not_eql?(left, right)
  !left.eql?(right)
end
number?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 61
def number?(input)
  true if Float(input)
rescue ArgumentError, TypeError
  false
end
odd?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 91
def odd?(input)
  input.odd?
end
predicate(name, &block) click to toggle source
# File lib/dry/logic/predicates.rb, line 243
def predicate(name, &block)
  define_singleton_method(name, &block)
end
respond_to?(method, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 239
def respond_to?(method, input)
  input.respond_to?(method)
end
size?(size, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 115
def size?(size, input)
  case size
  when Integer then size.equal?(input.size)
  when Range, Array then size.include?(input.size)
  else
    raise ArgumentError, "+#{size}+ is not supported type for size? predicate."
  end
end
str?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 79
def str?(input)
  input.is_a?(String)
end
time?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 57
def time?(input)
  input.is_a?(Time)
end
true?(value) click to toggle source
# File lib/dry/logic/predicates.rb, line 193
def true?(value)
  value.equal?(true)
end
type?(type, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 15
def type?(type, input)
  input.is_a?(type)
end
uri?(schemes, input) click to toggle source
# File lib/dry/logic/predicates.rb, line 234
def uri?(schemes, input)
  uri_format = URI::DEFAULT_PARSER.make_regexp(schemes)
  format?(uri_format, input)
end
uuid_v1?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 209
def uuid_v1?(input)
  uuid_v1_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
  format?(uuid_v1_format, input)
end
uuid_v2?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 214
def uuid_v2?(input)
  uuid_v2_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
  format?(uuid_v2_format, input)
end
uuid_v3?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 219
def uuid_v3?(input)
  uuid_v3_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
  format?(uuid_v3_format, input)
end
uuid_v4?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 224
def uuid_v4?(input)
  uuid_v4_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
  format?(uuid_v4_format, input)
end
uuid_v5?(input) click to toggle source
# File lib/dry/logic/predicates.rb, line 229
def uuid_v5?(input)
  uuid_v5_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
  format?(uuid_v5_format, input)
end