Class: Atom::Xml::NamespaceHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/atom/xml/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, default = Atom::NAMESPACE) ⇒ NamespaceHandler

Returns a new instance of NamespaceHandler.



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

def initialize(root, default = Atom::NAMESPACE)
  @root = root
  @default = default
  @i = 0
  @map = {}
end

Instance Method Details

#each(&block) ⇒ Object



89
90
91
# File 'lib/atom/xml/parser.rb', line 89

def each(&block)
  @map.each(&block)
end

#get(ns) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/atom/xml/parser.rb', line 74

def get(ns)
  return @map[ns] if @map[ns]
  prefix = case ns
             when Atom::NAMESPACE
               'atom'
             when Atom::Pub::NAMESPACE
               'app'
             else
               "ns#{@i += 1}"
           end
  @root.add_namespace_definition(prefix, ns)
  @map[ns] = prefix
  prefix
end

#prefix(builder, ns) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/atom/xml/parser.rb', line 66

def prefix(builder, ns)
  if ns == @default
    builder
  else
    builder[get(ns)]
  end
end