Class: Sekken::XS::BaseType

Inherits:
Object
  • Object
show all
Defined in:
lib/sekken/xs/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, schemas, schema = {}) ⇒ BaseType

Returns a new instance of BaseType.



6
7
8
9
10
# File 'lib/sekken/xs/types.rb', line 6

def initialize(node, schemas, schema = {})
  @node = node
  @schemas = schemas
  @schema = schema
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



12
13
14
# File 'lib/sekken/xs/types.rb', line 12

def node
  @node
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/sekken/xs/types.rb', line 14

def [](key)
  @node[key]
end

#childrenObject



22
23
24
# File 'lib/sekken/xs/types.rb', line 22

def children
  @children ||= @node.element_children.map { |child| XS.build(child, @schemas, @schema) }
end

#collect_attributes(memo = []) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sekken/xs/types.rb', line 38

def collect_attributes(memo = [])
  children.each do |child|
    if child.kind_of? Attribute
      memo << child
    else
      memo = child.collect_attributes(memo)
    end
  end

  memo
end

#collect_child_elements(memo = []) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sekken/xs/types.rb', line 26

def collect_child_elements(memo = [])
  children.each do |child|
    if child.kind_of? Element
      memo << child
    else
      memo = child.collect_child_elements(memo)
    end
  end

  memo
end

#empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sekken/xs/types.rb', line 18

def empty?
  children.empty? || children.first.empty?
end

#inspectObject



50
51
52
53
54
55
56
# File 'lib/sekken/xs/types.rb', line 50

def inspect
  attributes = @node.attributes.
    inject({}) { |memo, (k, attr)| memo[k.to_s] = attr.value; memo }.
    map { |i| "%s=\"%s\"" % i }.
    join(' ')
  "<%s %s>" % [self.class, attributes]
end