Class: LocalPac::ProxyPac::PacParser

Inherits:
Object
  • Object
show all
Defined in:
lib/local_pac/proxy_pac/pac_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PacParser

Returns a new instance of PacParser.



12
13
14
15
16
17
18
19
20
21
# File 'lib/local_pac/proxy_pac/pac_parser.rb', line 12

def initialize(options = {})
  environment       = options.fetch(:environment, {})

  @file             = options.fetch(:file)
  @engine           = options.fetch(:engine, PACEngine.new(file: @file, environment: environment))
  @result_generator = options.fetch(:result_generator, PacResult)
  @stylist          = options.fetch(:stylist, PacResultHtmlStylist.new)
rescue KeyError => e
  fail ArgumentError, "Argument is missing: #{e.message}"
end

Instance Method Details

#find(uri) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/local_pac/proxy_pac/pac_parser.rb', line 23

def find(uri)
  uri = Addressable::URI.heuristic_parse(uri)

  raise Exceptions::GivenUrlInvalid, uri unless uri.host

  result = result_generator.new(engine.find(uri))
  stylist.style_me(result)

  result
end