Class: LibXMLJRuby::XML::Attr

Inherits:
Node
  • Object
show all
Defined in:
lib/libxml-jruby/xml/attr.rb

Constant Summary

Constants inherited from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAG_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REFERENCE_NODE, Node::NOTATION_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #[], #[]=, #attributes, #base, #child, #child?, #child_add, #children, #content, #content=, #copy, #doc, #document?, #each, #each_element, #eql?, #equal?, #find, #find_first, #first, #last, #name=, #next, #next?, #node_type, #node_type_name, #prev, #prev?, #to_s

Constructor Details

#initialize(node, name, value, ns = nil) ⇒ Attr

Returns a new instance of Attr.



15
16
17
18
# File 'lib/libxml-jruby/xml/attr.rb', line 15

def initialize(node, name, value, ns = nil)
  self.java_obj = node.java_obj
  java_obj.set_attribute(name, value)
end

Instance Attribute Details

#java_objObject

Returns the value of attribute java_obj.



13
14
15
# File 'lib/libxml-jruby/xml/attr.rb', line 13

def java_obj
  @java_obj
end

Class Method Details

.from_java(java_obj) ⇒ Object



5
6
7
8
9
10
# File 'lib/libxml-jruby/xml/attr.rb', line 5

def from_java(java_obj)
  return nil unless java_obj
  a = allocate
  a.java_obj = java_obj
  a
end

Instance Method Details

#nameObject



32
33
34
# File 'lib/libxml-jruby/xml/attr.rb', line 32

def name
  java_obj.respond_to?(:name) ? java_obj.name : java_obj.node_name
end

#parentObject



28
29
30
# File 'lib/libxml-jruby/xml/attr.rb', line 28

def parent
  LibXMLJRuby::XML::Node.from_java(java_obj.owner_element)
end

#parent?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/libxml-jruby/xml/attr.rb', line 24

def parent?
  !!parent
end

#remove!Object



20
21
22
# File 'lib/libxml-jruby/xml/attr.rb', line 20

def remove!
  java_obj.owner_element.remove_attribute(name)
end

#valueObject



36
37
38
# File 'lib/libxml-jruby/xml/attr.rb', line 36

def value
  java_obj.value
end

#value=(value) ⇒ Object

Raises:

  • (TypeError)


40
41
42
43
# File 'lib/libxml-jruby/xml/attr.rb', line 40

def value=(value)
  raise TypeError if value.nil?
  java_obj.value = value
end