Sha256: 49c0540067726a6a4d9b3542cbf13545628db5d83d2a69e6011642e9fad9bfb5

Contents?: true

Size: 1.12 KB

Versions: 47

Compression:

Stored size: 1.12 KB

Contents

module Ruboto
  module Util
    module ScanInAPI
      ###########################################################################
      #
      # Scan the XML file. Much faster than using REXML.
      #

      def scan_in_api(file)
        require 'strscan'
        doc = StringScanner.new(file)
        Thread.current[:api] = XMLElement.new
        parents = [Thread.current[:api]]

        while not doc.eos?
          doc.scan(/</)
          if doc.scan(/\/\w+>/)
            parents.pop
          else
            name = doc.scan(/\w+/)
            doc.scan(/\s+/)
            values = {}
            while not (term = doc.scan(/[\/>]/))
              key = doc.scan(/\w+/)
              doc.scan(/='/)
              value = doc.scan(/[^']*/)
              doc.scan(/'\s*/)
              values[key] = value.include?("&") ? value.gsub('&lt;', '<').gsub('&gt;', '>').gsub('&quot;', "\"") : value
            end
            element = parents[-1].add_element(name, values)
            parents.push(element) if term == ">"
            doc.scan(/>/) if term == "/"
          end
        end

        Thread.current[:api]
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
ruboto-1.6.1 lib/ruboto/util/scan_in_api.rb
ruboto-1.6.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.5.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.4.1 lib/ruboto/util/scan_in_api.rb
ruboto-1.4.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.3.1 lib/ruboto/util/scan_in_api.rb
ruboto-1.3.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.2.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.1.2 lib/ruboto/util/scan_in_api.rb
ruboto-1.1.1 lib/ruboto/util/scan_in_api.rb
ruboto-1.1.0 lib/ruboto/util/scan_in_api.rb
ruboto-1.0.3 lib/ruboto/util/scan_in_api.rb
ruboto-1.0.2 lib/ruboto/util/scan_in_api.rb
ruboto-1.0.1 lib/ruboto/util/scan_in_api.rb
ruboto-1.0.0 lib/ruboto/util/scan_in_api.rb
ruboto-0.16.0 lib/ruboto/util/scan_in_api.rb
ruboto-0.15.0 lib/ruboto/util/scan_in_api.rb
ruboto-0.14.0 lib/ruboto/util/scan_in_api.rb
ruboto-0.13.0 lib/ruboto/util/scan_in_api.rb
ruboto-0.12.0 lib/ruboto/util/scan_in_api.rb