Method: Bundler::URI::RFC2396_Parser#initialize

Defined in:
lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb

#initialize(opts = {}) ⇒ RFC2396_Parser

Synopsis

Bundler::URI::Parser.new([opts])

Args

The constructor accepts a hash as options for parser. Keys of options are pattern names of Bundler::URI components and values of options are pattern strings. The constructor generates set of regexps for parsing URIs.

You can use the following keys:

* :ESCAPED (Bundler::URI::PATTERN::ESCAPED in default)
* :UNRESERVED (Bundler::URI::PATTERN::UNRESERVED in default)
* :DOMLABEL (Bundler::URI::PATTERN::DOMLABEL in default)
* :TOPLABEL (Bundler::URI::PATTERN::TOPLABEL in default)
* :HOSTNAME (Bundler::URI::PATTERN::HOSTNAME in default)

Examples

p = Bundler::URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
u = p.parse("http://example.jp/%uABCD") #=> #<Bundler::URI::HTTP http://example.jp/%uABCD>
Bundler::URI.parse(u.to_s) #=> raises Bundler::URI::InvalidURIError

s = "http://example.com/ABCD"
u1 = p.parse(s) #=> #<Bundler::URI::HTTP http://example.com/ABCD>
u2 = Bundler::URI.parse(s) #=> #<Bundler::URI::HTTP http://example.com/ABCD>
u1 == u2 #=> true
u1.eql?(u2) #=> false
[View source]

99
100
101
102
103
104
105
106
107
# File 'lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb', line 99

def initialize(opts = {})
  @pattern = initialize_pattern(opts)
  @pattern.each_value(&:freeze)
  @pattern.freeze

  @regexp = initialize_regexp(@pattern)
  @regexp.each_value(&:freeze)
  @regexp.freeze
end