Module: Doodle::EscapeXML
- Defined in:
- lib/doodle/xml.rb
Constant Summary collapse
- ESCAPE =
{ '&' => '&', '"' => '"', '>' => '>', '<' => '<' }
Class Method Summary collapse
Class Method Details
.escape(s) ⇒ Object
13 14 15 |
# File 'lib/doodle/xml.rb', line 13 def self.escape(s) s.to_s.gsub(/[&"><]/) { |special| ESCAPE[special] } end |
.unescape(s) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/doodle/xml.rb', line 16 def self.unescape(s) ESCAPE.inject(s.to_s) do |str, (k, v)| # don't use gsub! here - don't want to modify argument str.gsub(v, k) end end |