Class: Atom::Xml::NamespaceMap

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

Instance Method Summary (collapse)

Constructor Details

- (NamespaceMap) initialize(default = Atom::NAMESPACE)

Returns a new instance of NamespaceMap



49
50
51
52
53
# File 'lib/atom/xml/parser.rb', line 49

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

Instance Method Details

- (Object) each(&block)



73
74
75
# File 'lib/atom/xml/parser.rb', line 73

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

- (Object) get(ns)



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

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

- (Object) prefix(ns, element)



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

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