Sha256: 9bafa2251b858b486e06204805b6734e4ec9d38dbe1328b91bb1a292de1dfa89

Contents?: true

Size: 750 Bytes

Versions: 2

Compression:

Stored size: 750 Bytes

Contents

%w(scheme host path query).each do |m|
  require_relative "./#{m}"
end

module UrlRegexp
  class Root < Node
    def initialize(options = {})
      @scheme = Scheme.new(options)
      @host = Host.new(options)
      @path = Path.new(nil, nil, options)
      @query = Query.new(options)
      @options = options
    end

    def append(url)
      url = URI(url) unless url.is_a?(URI)
      @path.append(url.path)
      @scheme.append(url.scheme)
      @host.append(url.host)
      @query.append(url.query)
    end

    def to_regexp_s
      s = '^' +
          @scheme.to_regexp_s +
          @host.to_regexp_s +
          @path.to_regexp_s +
          @query.to_regexp_s +
          '(#|$)'
      s.sub('(\\?.*)?(#|$)', '([?#]|$)')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
url_regexp-0.1.4 lib/url_regexp/root.rb
url_regexp-0.1.3 lib/url_regexp/root.rb