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



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

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

Instance Method Details

#each(&block) ⇒ Object



83
84
85
# File 'lib/atom/xml/parser.rb', line 83

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

#get(ns) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/atom/xml/parser.rb', line 73

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



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

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