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

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/vtd/xml/node/attributes.rb', line 18

def [](key)
  find_attribute(key)
end

#attributesObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/vtd/xml/node/attributes.rb', line 7

def attributes
  attributes = {}

  @auto_pilot.select_attr('*')
  while (i = @auto_pilot.iterate_attr) != -1
    attributes[string_from_index i] = string_from_index i + 1
  end

  attributes
end

#fetch(*args) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vtd/xml/node/attributes.rb', line 26

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

#slice(*keys) ⇒ Object



22
23
24
# File 'lib/vtd/xml/node/attributes.rb', line 22

def slice(*keys)
  Hash[*keys.flat_map { |key| [key, find_attribute(key)] }]
end