lib/eco/language/match.rb in eco-helpers-1.5.1 vs lib/eco/language/match.rb in eco-helpers-1.5.2
- old
+ new
@@ -1,30 +1,40 @@
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) }
+ 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?
- return match?(at , value, mode.new.reset_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)
- return match?(value, at, mode.new.reset_pattern)
+ 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?
- return value.all?(&out_match) # defaults to EVERY
+ 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?
- return at.any?(&in_match) # defaullts to OR
+ at.any?(&in_match) # defaullts to OR
when at.is_a?(Regexp)
- return at.match?(value)
+ indent_msg.call("(#{at.inspect}) at.match?(value); value: #{value}")
+ at.match?(value)
when value.is_a?(Regexp)
- return value.match?(at)
+ 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