Class: Dub::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
# File 'lib/dub/parser.rb', line 7

def initialize(filepath)
  @current_dir = File.dirname(filepath)
  @xml = Hpricot::XML(File.read(filepath))
end

Instance Method Details

#[](name) ⇒ Object



12
13
14
# File 'lib/dub/parser.rb', line 12

def [](name)
  namespaces[name.to_s] || groups[name.to_s]
end

#group(name) ⇒ Object



20
21
22
# File 'lib/dub/parser.rb', line 20

def group(name)
  groups[name.to_s]
end

#groupsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/dub/parser.rb', line 35

def groups
  @groups ||= begin
    groups = {}
    (@xml/'compounddef[@kind=group]').each do |namespace|
      name = (namespace/"compoundname").innerHTML
      groups[name] = Dub::Group.new(name, namespace, @current_dir)
    end
    groups
  end
end

#namespace(name) ⇒ Object



16
17
18
# File 'lib/dub/parser.rb', line 16

def namespace(name)
  namespaces[name.to_s]
end

#namespacesObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/dub/parser.rb', line 24

def namespaces
  @namespaces ||= begin
    ns = {}
    (@xml/'compounddef[@kind=namespace]').each do |namespace|
      name = (namespace/"compoundname").innerHTML
      ns[name] = Dub::Namespace.new(name, namespace, @current_dir)
    end
    ns
  end
end