Sha256: 545fcd68a513cf2231f5c404dbee3212b6afb8633b8a1e54f0acc6f027e35df3

Contents?: true

Size: 719 Bytes

Versions: 1

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true
module Speculation
  # @private
  class RegexSpec < Spec
    include NamespacedSymbols
    S = Speculation

    def initialize(regex)
      @regex = regex
    end

    def conform(value)
      if value.nil? || Utils.collection?(value)
        S.re_conform(@regex, value)
      else
        S::INVALID
      end
    end

    def explain(path, via, inn, value)
      if value.nil? || Utils.collection?(value)
        S.re_explain(path, via, inn, @regex, value || [])
      else
        [{ :path => path, :val => value, :via => via, :in => inn }]
      end
    end

    def gen(overrides, path, rmap)
      return @gen if @gen

      S.re_gen(@regex, overrides, path, rmap)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
speculation-0.3.0 lib/speculation/spec/regex_spec.rb