Class: ConfigureS3Website::XmlHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/configure-s3-website/xml_helper.rb

Class Method Summary collapse

Class Method Details

.hash_to_api_xml(hash = {}, indent = 0) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/configure-s3-website/xml_helper.rb', line 3

def self.hash_to_api_xml(hash={}, indent=0)
  "".tap do |body|
    hash.each do |key, value|
      key_name = key.sub(/^[a-z\d]*/) { $&.capitalize }.gsub(/(?:_|(\/))([a-z\d]*)/) { $2.capitalize }
      value = value.is_a?(Hash) ? self.hash_to_api_xml(value, indent+1) : value
      body << "\n"
      body << " " * indent * 2 # 2-space indentation formatting for xml
      body << "<#{key_name}>#{value}</#{key_name}>"
    end
  end
end