Class: PrepareRegexp

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ PrepareRegexp

Returns a new instance of PrepareRegexp.



2
3
4
# File 'lib/regexp.rb', line 2

def initialize(pattern)
  @s = pattern
end

Class Method Details

.each(options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/regexp.rb', line 25

def self.each(options)
  options[:filter].each do |f|
    if f.regexp.is_a? PrepareRegexp
      f.regexp = yield :filter, f.regexp
    end
  end
  options.each do |k, v|
    if v.is_a? PrepareRegexp
      options[k] = yield k, v
    end
  end
end

Instance Method Details

#create(ignore_case, verbose, roman, &b) ⇒ Object

end



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/regexp.rb', line 11

def create(ignore_case, verbose, roman, &b)
  begin
    c = verbose ? VerboseRegexp : Regexp
    o = ignore_case ? Regexp::IGNORECASE : nil
    s = roman ? @s.gsub('(roman)', "(#{Regexp.ROMAN_PATTERN})") : @s 
    r = c.new s, o
    r.result_proc = b if verbose
    r
  rescue
    b.call :error, "Error parsing regular expression:\n#{$!}"
    nil
  end
end