<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
require 'rubygems/source'

class Gem::SourceList
  def initialize
    @sources = []
  end

  attr_reader :sources

  def self.from(ary)
    list = new

    if ary
      ary.each do |x|
        list << x
      end
    end

    return list
  end

  def initialize_copy(other)
    @sources = @sources.dup
  end

  def <<(obj)
    src = case obj
          when URI
            Gem::Source.new(obj)
          when Gem::Source
            obj
          else
            Gem::Source.new(URI.parse(obj))
          end

    @sources << src
    src
  end

  def replace(other)
    @sources.clear

    other.each do |x|
      self << x
    end

    self
  end

  def each
    @sources.each { |s| yield s.uri.to_s }
  end

  def each_source(&b)
    @sources.each(&b)
  end

  def ==(other)
    to_a == other
  end

  def to_a
    @sources.map { |x| x.uri.to_s }
  end

  alias_method :to_ary, :to_a

  def first
    @sources.first
  end

  def include?(other)
    if other.kind_of? Gem::Source
      @sources.include? other
    else
      @sources.find { |x| x.uri.to_s == other.to_s }
    end
  end

  def delete(uri)
    if uri.kind_of? Gem::Source
      @sources.delete uri
    else
      @sources.delete_if { |x| x.uri.to_s == uri.to_s }
    end
  end
end
