module Eco module Language def match?(value, at, mode = MatchModifier.new) out_match = ->(v) { match?(v, at, mode) } in_match = ->(a) { match?(value, a, mode) } case when mode.reverse? return match?(at , value, mode.new.reset_reverse) when mode.pattern? at = mode.to_regex(at) return match?(value, at, mode.new.reset_pattern) when value.is_a?(Array) return value.any?(&out_match) if mode.any? return value.all?(&out_match) # defaults to EVERY when at.is_a?(Array) return at.all?(&in_match) if mode.and? return at.any?(&in_match) # defaullts to OR when at.is_a?(Regexp) return at.match?(value) when value.is_a?(Regexp) return value.match?(at) else # final compare m = (value == at) || (mode.insensitive? && at&.downcase == value&.downcase) (mode.not?) ? !m : m end end end end