Method: FormatEngine::FormatRgx#initialize

Defined in:
lib/format_engine/format_spec/rgx.rb

#initialize(format) ⇒ FormatRgx

Setup a variable format specification.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/format_engine/format_spec/rgx.rb', line 21

def initialize(format)
  @long_name = format
  pre, _, post = format.partition('/')
  @short_name = pre + '/'

  exp, _, options = post.partition(/(?<=[^\\])\// )
  opt = (options.include?('x') ? Regexp::EXTENDED   : 0) |
        (options.include?('i') ? Regexp::IGNORECASE : 0) |
        (options.include?('m') ? Regexp::MULTILINE  : 0)

  @regex = Regexp.new(exp.gsub(/\\\//, '/'), opt)
end