Module: ParserCore::BaseBuilder
- Includes:
- Mega
- Defined in:
- lib/parser_core/base_builder.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add_attributes_and_namespaces(node) ⇒ Object
- #build_element(name, content, attributes = {}) ⇒ Object
- #builder ⇒ Object
- #initialize(name, data = {}, options = {}) ⇒ Object
- #to_xml ⇒ Object
Methods included from Mega
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/parser_core/base_builder.rb', line 5 def data @data end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/parser_core/base_builder.rb', line 5 def name @name end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
5 6 7 |
# File 'lib/parser_core/base_builder.rb', line 5 def namespaces @namespaces end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/parser_core/base_builder.rb', line 5 def @options end |
Instance Method Details
#add_attributes_and_namespaces(node) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/parser_core/base_builder.rb', line 45 def add_attributes_and_namespaces(node) if data.key? :attributes data[:attributes].each { |k, v| node[k] = v } end if namespaces.any? namespaces.each do |prefix, uri| node["xmlns:#{prefix}"] = uri end end node end |
#build_element(name, content, attributes = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/parser_core/base_builder.rb', line 27 def build_element(name, content, attributes = {}) attributes ||= attributes || {} element = Ox::Element.new(name) attributes.each { |k, v| element[k] = v } element << content if content element end |
#builder ⇒ Object
39 40 41 42 43 |
# File 'lib/parser_core/base_builder.rb', line 39 def builder root = Ox::Element.new(name) root end |
#initialize(name, data = {}, options = {}) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/parser_core/base_builder.rb', line 7 def initialize(name, data = {}, = {}) @name = name @data = data || {} @options = || {} @namespaces = [:namespaces] || {} end |
#to_xml ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/parser_core/base_builder.rb', line 14 def to_xml encoding = [:encoding] = { version: '1.0' } [:encoding] = encoding if encoding doc = Ox::Document.new() doc << builder = { with_xml: true } [:encoding] = encoding if encoding Ox.dump(doc, ) end |