Sha256: 2de0fba1e7342ab784c81b8f5b1abb8cd9ca01dba825fe2a39550d2afe251581

Contents?: true

Size: 1012 Bytes

Versions: 11

Compression:

Stored size: 1012 Bytes

Contents

require 'rubygems'
require 'hpricot'
require 'dub/namespace'

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

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

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

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

    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

    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
  end # Parser
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dub-1.0.0 lib/dub/parser.rb
dub-0.7.0 lib/dub/parser.rb
dub-0.6.6 lib/dub/parser.rb
dub-0.6.5 lib/dub/parser.rb
dub-0.6.4 lib/dub/parser.rb
dub-0.6.3 lib/dub/parser.rb
dub-0.6.2 lib/dub/parser.rb
dub-0.6.1 lib/dub/parser.rb
dub-0.6.0 lib/dub/parser.rb
dub-0.5.1 lib/dub/parser.rb
dub-0.5.0 lib/dub/parser.rb