Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash_to_xml.rb
Class Method Summary collapse
Class Method Details
.from_xml(xml_io) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/hash_to_xml.rb', line 5 def from_xml(xml_io) begin # we'll not use 'KeyToSymbol' because it doesn't symbolize the keys for node attributes opts = { 'ForceArray' => false, 'ForceContent' => false } # hash = XmlSimple.xml_in(xml_io, opts) return symbolize_keys(hash) rescue Exception => e raise BigBlueButton::BigBlueButtonException.new("Impossible to convert XML to hash. Error: #{e.}") end end |
.symbolize_keys(arg) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hash_to_xml.rb', line 16 def symbolize_keys(arg) case arg when Array arg.map { |elem| symbolize_keys elem } when Hash Hash[ arg.map { |key, value| k = key.is_a?(String) ? key.to_sym : key v = symbolize_keys value [k,v] }] else arg end end |