Class: Atom::Xml::NamespaceMap

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

Instance Method Summary collapse

Constructor Details

#initialize(default = Atom::NAMESPACE) ⇒ NamespaceMap

Returns a new instance of NamespaceMap.



51
52
53
54
55
# File 'lib/atom/xml/parser.rb', line 51

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

Instance Method Details

#each(&block) ⇒ Object



75
76
77
# File 'lib/atom/xml/parser.rb', line 75

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

#get(ns) ⇒ Object



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

def get(ns)
  if ns == Atom::NAMESPACE
    @map[ns] = "atom"
  elsif ns == Atom::Pub::NAMESPACE
    @map[ns] = "app"
  else
    @map[ns] or @map[ns] = "ns#{@i += 1}"
  end
end

#prefix(ns, element) ⇒ Object



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

def prefix(ns, element)
  if ns == @default
    element
  else
    "#{get(ns)}:#{element}"
  end
end