Class: EndiciaLabelServer::Builders::BuilderBase Abstract
- Inherits:
-
Object
- Object
- EndiciaLabelServer::Builders::BuilderBase
- Includes:
- Exceptions, Ox
- Defined in:
- lib/endicia_label_server/builders/builder_base.rb
Overview
This class is abstract.
The BuilderBase class builds Endicia XML Objects.
Direct Known Subclasses
ChangePassPhraseBuilder, PostageLabelBuilder, PostageRateBuilder, PostageRatesBuilder, UserSignUpBuilder
Instance Attribute Summary collapse
-
#document ⇒ Ox::Document
The XML Document being built.
-
#root ⇒ Ox::Element
The XML Root.
Instance Method Summary collapse
- #add(key, value, parent_element = nil) ⇒ Object
- #assign_root_attributes(root_attributes) ⇒ Object
-
#initialize(root_name, opts = {}, root_attributes = nil) ⇒ void
constructor
Initializes a new BuilderBase object.
- #to_http_post ⇒ Object
-
#to_xml(opts = {}) ⇒ String
Returns a String representation of the XML document being built.
Constructor Details
#initialize(root_name, opts = {}, root_attributes = nil) ⇒ void
Initializes a new EndiciaLabelServer::Builders::BuilderBase object
23 24 25 26 27 28 29 30 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 23 def initialize(root_name, opts = {}, root_attributes = nil) initialize_xml_roots(root_name) assign_root_attributes(root_attributes) if root_attributes document << root opts.each_pair { |k, v| add(k, v, root) } end |
Instance Attribute Details
#document ⇒ Ox::Document
The XML Document being built
12 13 14 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 12 def document @document end |
#root ⇒ Ox::Element
The XML Root
12 13 14 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 12 def root @root end |
Instance Method Details
#add(key, value, parent_element = nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 32 def add(key, value, parent_element = nil) parent = parent_element || root key = (key.is_a? String) ? key : Util.camelize(key) return add_element_from_hash_values(parent, key, value) if value.is_a?(Hash) return add_element_from_array_items(parent, key, value) if value.is_a?(Array) return add_single_element(parent, key, value) end |
#assign_root_attributes(root_attributes) ⇒ Object
41 42 43 44 45 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 41 def assign_root_attributes(root_attributes) root_attributes.each do |attr_key, attr_value| root[Util.camelize(attr_key)] = attr_value end end |
#to_http_post ⇒ Object
54 55 56 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 54 def to_http_post "#{post_field}=#{to_xml}" end |
#to_xml(opts = {}) ⇒ String
Returns a String representation of the XML document being built
50 51 52 |
# File 'lib/endicia_label_server/builders/builder_base.rb', line 50 def to_xml(opts = {}) Ox.to_xml(document, opts) end |