Class: Regexp
Direct Known Subclasses
Class Method Summary collapse
- .ROMAN ⇒ Object
-
.ROMAN_PATTERN ⇒ Object
All groups are non-capturing!.
Instance Method Summary collapse
Class Method Details
.ROMAN ⇒ Object
9 10 11 |
# File 'lib/innate/roman.rb', line 9 def self.ROMAN Regexp.new("^#{self.ROMAN_PATTERN}$", 'i') end |
.ROMAN_PATTERN ⇒ Object
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_roman ⇒ Object
13 14 15 16 |
# File 'lib/innate/roman.rb', line 13 def interpolate_roman # r = /\?([imx]*-[imx]*:[^(]\()roman(\).*)/ interpolate '(roman)', "(#{Regexp.ROMAN_PATTERN})" end |