Class: Qbxml::Hash

Inherits:
Hash
  • Object
show all
Includes:
Types
Defined in:
lib/qbxml/hash.rb

Overview

Constant Summary collapse

CONTENT_ROOT =
'__content__'.freeze
ATTR_ROOT =
'xml_attributes'.freeze
IGNORED_KEYS =
[ATTR_ROOT]

Constants included from Types

Types::ACRONYMS, Types::BIGDECIMAL_CAST, Types::BOOL_CAST, Types::DATE_CAST, Types::FLOAT_CAST, Types::INT_CAST, Types::STR_CAST, Types::TIME_CAST, Types::TYPE_MAP, Types::XML_DIRECTIVES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(hash, opts = {}, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/qbxml/hash.rb', line 15

def self.from_hash(hash, opts = {}, &block)
  key_proc = \
    if opts[:camelize]
      lambda { |k| k.camelize } 
    elsif opts[:underscore]
      lambda { |k| k.underscore } 
    end

  deep_convert(hash, opts, &key_proc)
end

.from_xml(xml, opts = {}) ⇒ Object



36
37
38
39
# File 'lib/qbxml/hash.rb', line 36

def self.from_xml(xml, opts = {})
  from_hash(
    xml_to_hash(Nokogiri::XML(xml).root, {}, opts), opts)
end

.to_xml(hash, opts = {}) ⇒ Object



30
31
32
33
34
# File 'lib/qbxml/hash.rb', line 30

def self.to_xml(hash, opts = {})
  opts[:root], hash = hash.first
  opts[:attributes] = hash.delete(ATTR_ROOT)
  hash_to_xml(hash, opts)
end

Instance Method Details

#to_xml(opts = {}) ⇒ Object



26
27
28
# File 'lib/qbxml/hash.rb', line 26

def to_xml(opts = {})
  hash = self.class.to_xml(self, opts)
end