class Sekken::XML::Element

Attributes

attributes[RW]

Public: The attributes.

base_type[RW]

Public: The base name for a simple type element.

children[RW]

Public: The child elements.

complex_type_id[RW]

Private: The complex type id for this element to track recursive type definitions.

form[RW]
name[RW]
namespace[RW]
parent[RW]
recursive_type[RW]

Public: The name of the recursive type definition if any.

singular[RW]

Public: Accessor for whether this is a single element.

singular?[RW]

Public: Accessor for whether this is a single element.

Public Class Methods

new() click to toggle source
# File lib/sekken/xml/element.rb, line 5
def initialize
  @children   = []
  @attributes = {}
  @recursive  = false
  @singular   = true
end

Public Instance Methods

complex_type?() click to toggle source

Public: Whether this element is a complex type.

# File lib/sekken/xml/element.rb, line 20
def complex_type?
  !simple_type?
end
recursive?() click to toggle source

Public: Whether or not this element’s type is defined recursively, meaning one of this element’s parents is of the same type as this element.

# File lib/sekken/xml/element.rb, line 33
def recursive?
  !!recursive_type
end
simple_type?() click to toggle source

Public: Whether this element is a simple type.

# File lib/sekken/xml/element.rb, line 15
def simple_type?
  !!base_type
end
to_a(memo = [], stack = []) click to toggle source

Public: Returns this element and its children as an Array of Hashes for inspection.

# File lib/sekken/xml/element.rb, line 50
def to_a(memo = [], stack = [])
  new_stack = stack + [name]
  data = { namespace: namespace, form: form, singular: singular? }

  unless attributes.empty?
    data[:attributes] = attributes.each_with_object({}) do |attribute, memo|
      memo[attribute.name] = { optional: attribute.optional? }
    end
  end

  if recursive?
    data[:recursive_type] = recursive_type
    memo << [new_stack, data]

  elsif simple_type?
    data[:type] = base_type
    memo << [new_stack, data]

  elsif complex_type?
    memo << [new_stack, data]

    children.each do |child|
      child.to_a(memo, new_stack)
    end

  end

  memo
end