Class: XSD::NamedElements
- Includes:
- Enumerable
- Defined in:
- lib/xsd/namedelements.rb
Constant Summary collapse
Instance Method Summary collapse
- #+(rhs) ⇒ Object
- #<<(rhs) ⇒ Object
- #[](idx) ⇒ Object
- #concat(rhs) ⇒ Object
- #delete(rhs) ⇒ Object
- #dup ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #find_all ⇒ Object
- #find_name(name) ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ NamedElements
constructor
A new instance of NamedElements.
- #keys ⇒ Object
- #size ⇒ Object
- #uniq ⇒ Object
- #uniq! ⇒ Object
Constructor Details
#initialize ⇒ NamedElements
Returns a new instance of NamedElements.
16 17 18 19 |
# File 'lib/xsd/namedelements.rb', line 16 def initialize @elements = [] @cache = {} end |
Instance Method Details
#+(rhs) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/xsd/namedelements.rb', line 74 def +(rhs) o = NamedElements.new o.elements = @elements + rhs.elements @cache.clear o end |
#<<(rhs) ⇒ Object
63 64 65 66 |
# File 'lib/xsd/namedelements.rb', line 63 def <<(rhs) @elements << rhs self end |
#[](idx) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/xsd/namedelements.rb', line 41 def [](idx) if idx.is_a?(Numeric) @elements[idx] else @cache[idx] ||= @elements.find { |item| item.name == idx } end end |
#concat(rhs) ⇒ Object
81 82 83 84 85 |
# File 'lib/xsd/namedelements.rb', line 81 def concat(rhs) @elements.concat(rhs.elements) @cache.clear self end |
#delete(rhs) ⇒ Object
68 69 70 71 72 |
# File 'lib/xsd/namedelements.rb', line 68 def delete(rhs) rv = @elements.delete(rhs) @cache.clear rv end |
#dup ⇒ Object
21 22 23 24 25 |
# File 'lib/xsd/namedelements.rb', line 21 def dup o = NamedElements.new o.elements = @elements.dup o end |
#each ⇒ Object
57 58 59 60 61 |
# File 'lib/xsd/namedelements.rb', line 57 def each @elements.each do |element| yield(element) end end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/xsd/namedelements.rb', line 33 def empty? size == 0 end |
#find_all ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/xsd/namedelements.rb', line 98 def find_all o = NamedElements.new each do |ele| o << ele if yield(ele) end o end |
#find_name(name) ⇒ Object
49 50 51 |
# File 'lib/xsd/namedelements.rb', line 49 def find_name(name) @elements.find { |item| item.name.name == name } end |
#freeze ⇒ Object
27 28 29 30 31 |
# File 'lib/xsd/namedelements.rb', line 27 def freeze super @elements.freeze self end |
#keys ⇒ Object
53 54 55 |
# File 'lib/xsd/namedelements.rb', line 53 def keys collect { |element| element.name } end |
#size ⇒ Object
37 38 39 |
# File 'lib/xsd/namedelements.rb', line 37 def size @elements.size end |
#uniq ⇒ Object
87 88 89 90 91 |
# File 'lib/xsd/namedelements.rb', line 87 def uniq o = NamedElements.new o.elements = uniq_elements o end |
#uniq! ⇒ Object
93 94 95 96 |
# File 'lib/xsd/namedelements.rb', line 93 def uniq! @elements.replace(uniq_elements) @cache.clear end |