Class: XSD::NamedElements

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/xsd/namedelements.rb

Constant Summary collapse

Empty =
NamedElements.new.freeze

Instance Method Summary collapse

Methods included from Enumerable

#inject

Constructor Details

#initializeNamedElements

Returns a new instance of NamedElements.



15
16
17
18
# File 'lib/xsd/namedelements.rb', line 15

def initialize
  @elements = []
  @cache = {}
end

Instance Method Details

#+(rhs) ⇒ Object



73
74
75
76
77
78
# File 'lib/xsd/namedelements.rb', line 73

def +(rhs)
  o = NamedElements.new
  o.elements = @elements + rhs.elements
  @cache.clear
  o
end

#<<(rhs) ⇒ Object



62
63
64
65
# File 'lib/xsd/namedelements.rb', line 62

def <<(rhs)
  @elements << rhs
  self
end

#[](idx) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/xsd/namedelements.rb', line 40

def [](idx)
  if idx.is_a?(Numeric)
    @elements[idx]
  else
    @cache[idx] ||= @elements.find { |item| item.name == idx }
  end
end

#concat(rhs) ⇒ Object



80
81
82
83
84
# File 'lib/xsd/namedelements.rb', line 80

def concat(rhs)
  @elements.concat(rhs.elements)
  @cache.clear
  self
end

#delete(rhs) ⇒ Object



67
68
69
70
71
# File 'lib/xsd/namedelements.rb', line 67

def delete(rhs)
  rv = @elements.delete(rhs)
  @cache.clear
  rv
end

#dupObject



20
21
22
23
24
# File 'lib/xsd/namedelements.rb', line 20

def dup
  o = NamedElements.new
  o.elements = @elements.dup
  o
end

#eachObject



56
57
58
59
60
# File 'lib/xsd/namedelements.rb', line 56

def each
  @elements.each do |element|
    yield(element)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/xsd/namedelements.rb', line 32

def empty?
  size == 0
end

#find_allObject



97
98
99
100
101
102
103
# File 'lib/xsd/namedelements.rb', line 97

def find_all
  o = NamedElements.new
  each do |ele|
    o << ele if yield(ele)
  end
  o
end

#find_name(name) ⇒ Object



48
49
50
# File 'lib/xsd/namedelements.rb', line 48

def find_name(name)
  @elements.find { |item| item.name.name == name }
end

#freezeObject



26
27
28
29
30
# File 'lib/xsd/namedelements.rb', line 26

def freeze
  super
  @elements.freeze
  self
end

#keysObject



52
53
54
# File 'lib/xsd/namedelements.rb', line 52

def keys
  collect { |element| element.name }
end

#sizeObject



36
37
38
# File 'lib/xsd/namedelements.rb', line 36

def size
  @elements.size
end

#uniqObject



86
87
88
89
90
# File 'lib/xsd/namedelements.rb', line 86

def uniq
  o = NamedElements.new
  o.elements = uniq_elements
  o
end

#uniq!Object



92
93
94
95
# File 'lib/xsd/namedelements.rb', line 92

def uniq!
  @elements.replace(uniq_elements)
  @cache.clear
end