Sha256: 56957d91c87c12955c36eb4a8d9d942d3061360ebbd1cc14059552e64c924650

Contents?: true

Size: 486 Bytes

Versions: 1

Compression:

Stored size: 486 Bytes

Contents

require_relative './node'

module UrlRegexp
  class Scheme < Node
    def initialize
      @schemes = Set.new
    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

1 entries across 1 versions & 1 rubygems

Version Path
url_regexp-0.1.2 lib/url_regexp/scheme.rb