Class: Washcloth::Formatters::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/washcloth.rb

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Xml

Returns a new instance of Xml.



32
33
34
# File 'lib/washcloth.rb', line 32

def initialize(filter)
  @filter = filter
end

Instance Method Details

#regexpObject



36
37
38
# File 'lib/washcloth.rb', line 36

def regexp
  /<#{@filter.name}>(?<inner>.*)<\/#{@filter.name}>/mi
end

#run(value) ⇒ Object



40
41
42
43
44
45
# File 'lib/washcloth.rb', line 40

def run(value)
  value.gsub(regexp) do |match|
    last_match = Regexp.last_match[:inner]
    match.sub(last_match, @filter.filter[last_match])
  end
end