Module: SimpleJSONSchema::RegexHelper

Defined in:
lib/simple_json_schema/regex_helper.rb

Constant Summary collapse

RUBY_REGEX_ANCHORS_TO_ECMA_262 =
{
  bos: 'A',
  eos: 'z',
  bol: '\A',
  eol: '\z'
}.freeze

Class Method Summary collapse

Class Method Details

.ecma_262_regex(pattern, cache) ⇒ Object


13
14
15
16
17
18
19
20
21
# File 'lib/simple_json_schema/regex_helper.rb', line 13

def ecma_262_regex(pattern, cache)
  cache.fetch(pattern) do
    Regexp.new(
      Regexp::Scanner.scan(pattern).map do |type, token, text|
        type == :anchor ? RUBY_REGEX_ANCHORS_TO_ECMA_262.fetch(token, text) : text
      end.join
    )
  end
end