Class: BigBlueButton::BigBlueButtonHash

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

Class Method Summary collapse

Class Method Details

.from_xml(xml_io) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bigbluebutton_hash_to_xml.rb', line 6

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
    exception = BigBlueButtonException.new("Impossible to convert XML to hash. Error: #{e.message}")
    exception.key = 'XMLConversionError'  
    raise exception
  end
end

.symbolize_keys(arg) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bigbluebutton_hash_to_xml.rb', line 19

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