Class: Wiris::EReg

Inherits:
Object
  • Object
show all
Defined in:
lib/src-generic/EReg.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, opts = nil) ⇒ EReg

Returns a new instance of EReg.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/src-generic/EReg.rb', line 17

def initialize(pattern, opts=nil)
  flags = 0
  if not opts.nil?
    for i in 0..opts.length
      case opts[i]
      when "i"
        flags += Regexp::IGNORECASE
      when "s"
        flags +=  Regexp::MULTILINE
      when "m"
        flags +=  Regexp::MULTILINE
      end
    end
  end
  @regex = Regexp.new(pattern, flags)
end

Instance Method Details

#match(str) ⇒ Object



13
14
15
# File 'lib/src-generic/EReg.rb', line 13

def match
  @match
end

#match=(match) ⇒ Object



10
11
12
# File 'lib/src-generic/EReg.rb', line 10

def match=(match)
  @match=match
end

#matched(n) ⇒ Object



52
53
54
# File 'lib/src-generic/EReg.rb', line 52

def matched(n)
  return @match[n]
end

#regexObject



6
7
8
# File 'lib/src-generic/EReg.rb', line 6

def regex
  @regex
end

#regex=(regex) ⇒ Object



3
4
5
# File 'lib/src-generic/EReg.rb', line 3

def regex=(regex)
  @regex=regex
end

#replace(str, by) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/src-generic/EReg.rb', line 43

def replace(str, by)
  @match = @regex.match(str)
  if @match.nil?
    return str
  else
    return str.gsub(@match.regexp, by)
  end
end