Class: Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/client_side_validations/core_ext/regexp.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/client_side_validations/core_ext/regexp.rb', line 2

def as_json(options = nil)
  str = inspect
    .sub('\\A' , '^')
    .sub('\\Z' , '$')
    .sub('\\z' , '$')
    .sub(/^\// , '')
    .sub(/\/[a-z]*$/ , '')
    .gsub(/\(\?#.+\)/ , '')
    .gsub(/\(\?-\w+:/ , '(')
    .gsub(/\s/ , '')
  opts = []
  opts << 'i' if (self.options & Regexp::IGNORECASE) > 0
  opts << 'm' if (self.options & Regexp::MULTILINE) > 0
  { source: Regexp.new(str).source, options: opts.join }
end

#encode_json(encoder) ⇒ Object



22
23
24
# File 'lib/client_side_validations/core_ext/regexp.rb', line 22

def encode_json(encoder)
  inspect
end

#to_json(options = nil) ⇒ Object



18
19
20
# File 'lib/client_side_validations/core_ext/regexp.rb', line 18

def to_json(options = nil)
  as_json(options)
end