Sha256: 2970e5adbfdc4e4367b2601e5c179b3791fd11e5d159647d389801c5fdc41150

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
module ProxyPacRb
  # Proxy Pac parser
  #
  # @example Usage
  #
  # parser = Parser.new
  # parser.load('http://example.com/proxy.pac')
  # parser.read('file.pac')
  #
  # string = ''
  # parser.source(string)
  class Parser
    private

    attr_reader :parser, :loader, :linter

    public

    def initialize(*args)
      if args.first.is_a? Hash
        @parser = ProxyPacParser.new(**args.first)
      else
        $stderr.puts 'Deprecated: Use of positional parameters. Please use named parameters: environment: Environment.new.'
        @parser = ProxyPacParser.new(environment: args.first)
      end

      @loader = ProxyPacLoader.new
      @linter = ProxyPacLinter.new
    end

    def parse(source)
      pac_file = ProxyPacFile.new source: source

      loader.load(pac_file)
      linter.lint(pac_file)

      unless pac_file.valid?
        $stderr.puts %(proxy.pac "#{pac_file.source}" is invalid.)

        return
      end

      parser.parse(pac_file)
    end

    def load(*args)
      $stderr.puts 'Deprecated: #load. Please use #parse instead.'

      parse(*args)
    end

    def read(*args)
      $stderr.puts 'Deprecated: #read. Please use #parse instead.'

      parse(*args)
    end

    def source(*args)
      $stderr.puts 'Deprecated: #source. Please use #parse instead.'

      parse(*args)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxy_pac_rb-0.4.2 lib/proxy_pac_rb/parser.rb
proxy_pac_rb-0.4.0 lib/proxy_pac_rb/parser.rb