Class: Moxml::Namespace

Inherits:
Node
  • Object
show all
Defined in:
lib/moxml/namespace.rb

Instance Attribute Summary

Attributes inherited from Node

#native

Instance Method Summary collapse

Methods inherited from Node

#add_next_sibling, #add_previous_sibling, #children, #column, #inner_html, #inner_html=, #line, #next_sibling, #outer_html, #parent, #path, #previous_sibling, #remove, #replace, #text, #text=, wrap

Constructor Details

#initialize(prefix_or_native = nil, uri = nil) ⇒ Namespace

Returns a new instance of Namespace.



3
4
5
6
7
8
9
10
# File 'lib/moxml/namespace.rb', line 3

def initialize(prefix_or_native = nil, uri = nil)
  case prefix_or_native
  when String
    super(adapter.create_namespace(nil, prefix_or_native, uri))
  else
    super(prefix_or_native)
  end
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
# File 'lib/moxml/namespace.rb', line 38

def ==(other)
  other.is_a?(Namespace) &&
    other.prefix == prefix &&
    other.uri == uri
end

#blank?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/moxml/namespace.rb', line 30

def blank?
  uri.nil? || uri.empty?
end

#namespace?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/moxml/namespace.rb', line 34

def namespace?
  true
end

#prefixObject



12
13
14
# File 'lib/moxml/namespace.rb', line 12

def prefix
  adapter.namespace_prefix(native)
end

#prefix=(new_prefix) ⇒ Object



16
17
18
19
# File 'lib/moxml/namespace.rb', line 16

def prefix=(new_prefix)
  adapter.set_namespace_prefix(native, new_prefix)
  self
end

#to_sObject



44
45
46
# File 'lib/moxml/namespace.rb', line 44

def to_s
  prefix ? "xmlns:#{prefix}='#{uri}'" : "xmlns='#{uri}'"
end

#uriObject



21
22
23
# File 'lib/moxml/namespace.rb', line 21

def uri
  adapter.namespace_uri(native)
end

#uri=(new_uri) ⇒ Object



25
26
27
28
# File 'lib/moxml/namespace.rb', line 25

def uri=(new_uri)
  adapter.set_namespace_uri(native, new_uri)
  self
end