Sha256: 1af7c133f0c6d7c4b7ee4a2d7da1712949943e555e2429e25d3a5ba402fa6ea9

Contents?: true

Size: 525 Bytes

Versions: 2

Compression:

Stored size: 525 Bytes

Contents

require_relative './node'

module UrlRegexp
  class Scheme < Node
    def initialize(options = {})
      @schemes = Set.new
      @options = options
    end

    def append(scheme)
      @schemes << scheme
    end

    def to_regexp_s
      schemes = @schemes.map { |s| Regexp.quote(s) }
      if schemes == %w(http https)
        'https?://'
      elsif 1 < @schemes.size
        "(#{schemes.join('|')})://"
      elsif 1 == @schemes.size
        "#{schemes.to_a.first}://"
      else
        ''
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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