Class: Xommelier::Xml::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/xommelier/xml/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}, &block) ⇒ Namespace

Returns a new instance of Namespace.



19
20
21
22
23
24
25
26
# File 'lib/xommelier/xml/namespace.rb', line 19

def initialize(uri, options = {}, &block)
  @uri     = uri
  @options = {}
  @as      = options.delete(:as)

  self.options = options
  scoped(&block) if block_given?
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#uriObject (readonly) Also known as: to_s, href

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#asObject



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

def as
  @as unless default?
end

#attribute_nameObject



66
67
68
# File 'lib/xommelier/xml/namespace.rb', line 66

def attribute_name
  default? ? 'xmlns' : "xmlns:#{as}"
end

#default?Boolean

Returns:



58
59
60
# File 'lib/xommelier/xml/namespace.rb', line 58

def default?
  uri.to_s == DEFAULT_NS
end

#inspectObject



70
71
72
# File 'lib/xommelier/xml/namespace.rb', line 70

def inspect
  %(#{attribute_name}="#{uri}")
end

#moduleObject



46
47
48
# File 'lib/xommelier/xml/namespace.rb', line 46

def module
  options[:module]
end

#nsObject



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

def ns
  Xommelier::Xml::Namespace.registry
end

#schemaObject



50
51
52
# File 'lib/xommelier/xml/namespace.rb', line 50

def schema
  self.module.schema
end

#scoped(&block) ⇒ Object



54
55
56
# File 'lib/xommelier/xml/namespace.rb', line 54

def scoped(&block)
  instance_exec(&block)
end

#to_hashObject



62
63
64
# File 'lib/xommelier/xml/namespace.rb', line 62

def to_hash
  { as.to_s => uri.to_s }
end