Sha256: ece773bf4a76049fe7335e955afb815fa49bc5e8b07191a344761a57f2f73804

Contents?: true

Size: 992 Bytes

Versions: 74

Compression:

Stored size: 992 Bytes

Contents

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

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
eco-helpers-1.5.1 lib/eco/language/match.rb
eco-helpers-1.5.0 lib/eco/language/match.rb
eco-helpers-1.4.2 lib/eco/language/match.rb
eco-helpers-1.3.19 lib/eco/language/match.rb
eco-helpers-1.4.1 lib/eco/language/match.rb
eco-helpers-1.4.0 lib/eco/language/match.rb
eco-helpers-1.3.18 lib/eco/language/match.rb
eco-helpers-1.3.17 lib/eco/language/match.rb
eco-helpers-1.3.16 lib/eco/language/match.rb
eco-helpers-1.3.15 lib/eco/language/match.rb
eco-helpers-1.3.14 lib/eco/language/match.rb
eco-helpers-1.3.13 lib/eco/language/match.rb
eco-helpers-1.3.12 lib/eco/language/match.rb
eco-helpers-1.3.11 lib/eco/language/match.rb
eco-helpers-1.3.10 lib/eco/language/match.rb
eco-helpers-1.3.9 lib/eco/language/match.rb
eco-helpers-1.3.8 lib/eco/language/match.rb
eco-helpers-1.3.7 lib/eco/language/match.rb
eco-helpers-1.3.6 lib/eco/language/match.rb
eco-helpers-1.3.5 lib/eco/language/match.rb