Class: DNZ::NamespaceArray
- Inherits:
-
Array
- Object
- Array
- DNZ::NamespaceArray
- Defined in:
- lib/dnz/namespace_array.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #inspect ⇒ Object
- #method_missing(symbol, *args, &block) ⇒ Object
-
#names ⇒ Object
An array of all unique node names in this array.
-
#namespaces ⇒ Object
An array of all unique namespaces in this array.
-
#text ⇒ Object
The combined text of all nodes in this array.
- #type ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dnz/namespace_array.rb', line 62 def method_missing(symbol, *args, &block) method = symbol.to_s if method =~ /(.*)\?$/ self[$1].any? elsif self.length == 1 && self.first.respond_to?(symbol) self.first.send(symbol, *args, &block) elsif args.empty? self[method] end end |
Instance Method Details
#[](index) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dnz/namespace_array.rb', line 23 def [](index) if index.is_a?(String) if (nodes = self.select{|node| node.namespace.prefix.downcase.to_s == index }).any? return NamespaceArray.new(nodes) end if (nodes = self.select{|node| node.name == index }).any? return NamespaceArray.new(nodes) end NamespaceArray.new else super end end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/dnz/namespace_array.rb', line 58 def inspect namespaces.collect {|namespace| '%s => [ %s ]' % [namespace, self[namespace].names.join(', ')] }.join(', ') end |
#names ⇒ Object
An array of all unique node names in this array.
44 45 46 |
# File 'lib/dnz/namespace_array.rb', line 44 def names map(&:name).map(&:downcase).uniq end |
#namespaces ⇒ Object
An array of all unique namespaces in this array.
49 50 51 |
# File 'lib/dnz/namespace_array.rb', line 49 def namespaces map(&:namespace).map(&:prefix).map(&:to_s).map(&:downcase).uniq end |
#text ⇒ Object
The combined text of all nodes in this array.
54 55 56 |
# File 'lib/dnz/namespace_array.rb', line 54 def text map(&:text).join end |
#type ⇒ Object
39 40 41 |
# File 'lib/dnz/namespace_array.rb', line 39 def type self['type'] end |