Class: XML::Smart::Dom::AttributeSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xml/smart_domattributeset.rb

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ AttributeSet

Returns a new instance of AttributeSet.



8
9
10
11
# File 'lib/xml/smart_domattributeset.rb', line 8

def initialize(element)
  @element = element
  @set = @element.attributes
end

Instance Method Details

#===(cls) ⇒ Object



13
# File 'lib/xml/smart_domattributeset.rb', line 13

def ===(cls); self.is_a? cls; end

#[](name, attr = false) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/xml/smart_domattributeset.rb', line 24

def [](name,attr=false)
  return nil unless has_attr?(name)
  if attr == false 
    @element.attribute(name).value
  else  
    Attribute.new(@element.attribute(name))
  end 
end

#[]=(name, value) ⇒ Object



32
33
34
# File 'lib/xml/smart_domattributeset.rb', line 32

def []=(name,value);
  @element[name] = value
end

#delete_all!Object



38
# File 'lib/xml/smart_domattributeset.rb', line 38

def delete_all!; @set.each { |k,a| a.remove }; end

#delete_at!(name) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/xml/smart_domattributeset.rb', line 48

def delete_at!(name)
  tmp = @set[name]
  if tmp.is_a?(Nokogiri::XML::Attr)
    tmp.remove
    true
  else
    false
  end
end

#delete_if!(&block) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/xml/smart_domattributeset.rb', line 58

def delete_if!(&block)
  return self if block.nil?
  @set.each do |k,node|
    node.remove if block.call(Dom::smart_helper(node))
  end
  self
end

#each(&block) ⇒ Object



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

def each(&block)
  return self if block.nil?
  @set.each do |k,node|
    block.call Dom::smart_helper(node)
  end
  self
end

#empty?Boolean

Returns:

  • (Boolean)


37
# File 'lib/xml/smart_domattributeset.rb', line 37

def empty?;      @set.empty?; end

#has_attr?(a) ⇒ Boolean Also known as: include?, attr?, member?

Returns:

  • (Boolean)


19
# File 'lib/xml/smart_domattributeset.rb', line 19

def has_attr?(a); @set.has_key?(a) end

#lengthObject



36
# File 'lib/xml/smart_domattributeset.rb', line 36

def length;      @set.length; end

#namesObject



15
16
17
# File 'lib/xml/smart_domattributeset.rb', line 15

def names
  @set.keys 
end