Module: VTD::Xml::Node::Attributes
- Included in:
- VTD::Xml::Node
- Defined in:
- lib/vtd/xml/node/attributes.rb
Constant Summary collapse
- AttributeMissing =
Class.new(StandardError)
Instance Method Summary collapse
- #[](key) ⇒ Object
- #attributes ⇒ Object
- #fetch(*args) ⇒ Object
- #initialize ⇒ Object
- #slice(*keys) ⇒ Object
Instance Method Details
#[](key) ⇒ Object
25 26 27 |
# File 'lib/vtd/xml/node/attributes.rb', line 25 def [](key) find_attribute(key) end |
#attributes ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vtd/xml/node/attributes.rb', line 12 def attributes return @attributes if @attributes @attributes = {} @auto_pilot.select_attr('*') while (i = @auto_pilot.iterate_attr) != -1 @attributes[string_from_index i] = string_from_index i + 1 end @attribute_cache = @attributes end |
#fetch(*args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vtd/xml/node/attributes.rb', line 33 def fetch(*args) if args.length == 2 key, default = *args else key = args.first end if item = find_attribute(key) return item end return yield(key) if block_given? return default if defined? default raise AttributeMissing, 'attribute not found' end |
#initialize ⇒ Object
7 8 9 10 |
# File 'lib/vtd/xml/node/attributes.rb', line 7 def initialize(*) @attribute_cache = {} @attributes = nil end |
#slice(*keys) ⇒ Object
29 30 31 |
# File 'lib/vtd/xml/node/attributes.rb', line 29 def slice(*keys) Hash[*keys.flat_map { |key| [key, find_attribute(key)] }] end |