Module: ODFReport::HashGsub

Included in:
Report, Section, Table
Defined in:
lib/odf-report/hash_gsub.rb

Constant Summary collapse

HTML_ESCAPE =
{ '&' => '&amp;',  '>' => '&gt;',   '<' => '&lt;', '"' => '&quot;' }

Instance Method Summary collapse

Instance Method Details

#hash_gsub!(_text, hash_of_values) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/odf-report/hash_gsub.rb', line 5

def hash_gsub!(_text, hash_of_values)
  hash_of_values.each do |key, val|
    txt = html_escape(val)
    txt = odf_linebreak(txt)
    _text.gsub!("[#{key.to_s.upcase}]", txt)
  end
end

#html_escape(s) ⇒ Object



15
16
17
18
# File 'lib/odf-report/hash_gsub.rb', line 15

def html_escape(s)
  return "" unless s
  s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
end

#node_hash_gsub!(_node, hash_of_values) ⇒ Object



25
26
27
28
29
# File 'lib/odf-report/hash_gsub.rb', line 25

def node_hash_gsub!(_node, hash_of_values)
  txt = _node.inner_html
  hash_gsub!(txt, hash_of_values)
  _node.inner_html = txt
end

#odf_linebreak(s) ⇒ Object



20
21
22
23
# File 'lib/odf-report/hash_gsub.rb', line 20

def odf_linebreak(s)
  return "" unless s
  s.to_s.gsub("\n", "<text:line-break/>")
end