Sha256: 831dafe83c66752b25c2b99161b4728def20fe187cbd9c609f1f2820b8edfb77
Contents?: true
Size: 1.66 KB
Versions: 162
Compression:
Stored size: 1.66 KB
Contents
module Eco module Language def match?(value, at, mode = MatchModifier.new, depth: 0) out_match = ->(v) { match?(v, at, mode, depth: depth + 1) } in_match = ->(a) { match?(value, a, mode, depth: depth + 1) } indent_msg = ->(m) { puts (" " * depth) + m if mode.debug? } case when mode.reverse? indent_msg.call("reverse value #{value} <--> at: #{at}") match?(at , value, mode.new.reset_reverse, depth: depth + 1) when mode.pattern? indent_msg.call("at to pattern: #{at}") at = mode.to_regex(at) match?(value, at, mode.new.reset_pattern, depth: depth + 1) when value.is_a?(Array) indent_msg.call("array #{value} value.#{mode.any?? "any?" : "all?"} match(v_item, at) at: #{at}") return value.any?(&out_match) if mode.any? value.all?(&out_match) # defaults to EVERY when at.is_a?(Array) indent_msg.call("array #{at} at.#{mode.and?? "all?" : "any?"} match(value, at_item). value: #{value}") return at.all?(&in_match) if mode.and? at.any?(&in_match) # defaullts to OR when at.is_a?(Regexp) indent_msg.call("(#{at.inspect}) at.match?(value); value: #{value}") at.match?(value) when value.is_a?(Regexp) indent_msg.call("(#{value.inspect}) value.match?(at); at: #{at}") value.match?(at) else # final compare indent_msg.call("-- final -- mode: #{mode.to_a}; value: #{value}; at: #{at}") m = (value == at) || (mode.insensitive? && at&.downcase == value&.downcase) (mode.not?) ? !m : m end end end end
Version data entries
162 entries across 162 versions & 1 rubygems