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



20
21
22
23
24
25
26
27
# File 'lib/xml/smart_domattributeset.rb', line 20

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

#[]=(name, value) ⇒ Object



28
29
30
# File 'lib/xml/smart_domattributeset.rb', line 28

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

#delete_all!Object



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

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

#delete_at!(name) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/xml/smart_domattributeset.rb', line 42

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

#delete_if!(&block) ⇒ Object



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

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

#each(&block) ⇒ Object



36
37
38
39
40
# File 'lib/xml/smart_domattributeset.rb', line 36

def each(&block)
  @set.each do |k,node|
    block.call Dom::smart_helper(node)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?;      @set.empty?; end

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

Returns:

  • (Boolean)


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

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

#lengthObject



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

def length;      @set.length; end