Class: Regexp

Inherits:
Object show all
Defined in:
lib/innate/roman.rb,
lib/innate/regexp.rb

Direct Known Subclasses

VerboseRegexp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ROMANObject



9
10
11
# File 'lib/innate/roman.rb', line 9

def self.ROMAN
  Regexp.new("^#{self.ROMAN_PATTERN}$", 'i')
end

.ROMAN_PATTERNObject

All groups are non-capturing!



5
6
7
# File 'lib/innate/roman.rb', line 5

def self.ROMAN_PATTERN
  '(?:M{0,4})(?:C[DM]|D?C{0,3})(?:X[LC]|L?X{0,3})(?:I[VX]|V?I{0,3})'
end

Instance Method Details

#interpolate(replace, new_pattern) ⇒ Object



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

def interpolate replace, new_pattern
  r = /^\(\?([imx]*)(-[imx]+)?:(.*?)#{Regexp.escape replace}(.*)\)$/
  m = r.match self.to_s
  if m
    s = "#{m[3]}#{new_pattern}#{m[4]}"
    o = m[1] || ''
    self.class.new(s, 
               (o.include?(?i) ? Regexp::IGNORECASE : 0) |
               (o.include?(?m) ? Regexp::MULTILINE : 0) |
               (o.include?(?x) ? Regexp::EXTENDED : 0))
  else
    self
  end
end

#interpolate_romanObject



13
14
15
16
# File 'lib/innate/roman.rb', line 13

def interpolate_roman
  #     r = /\?([imx]*-[imx]*:[^(]\()roman(\).*)/
  interpolate '(roman)', "(#{Regexp.ROMAN_PATTERN})"
end