Sha256: 3a85cab7e53ba617fe24fa5754402868493216c6f89284a2b507e533ba7506d0

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

module Earl
  class URL < HashInquirer
    def initialize( source )
      super parser.parse( source ).resolve rescue raise InvalidURLError
    end

    %w| scheme subdomain host port path search |.each do |part|
      define_method :"#{part}" do
        if self[ part.to_sym ].is_a? String
          StringInquirer.new self[ part.to_sym ]
        else
          self[ part.to_sym ]
        end
      end
      define_method :"#{part}=" do |value|
        raise InvalidURLError if part.to_sym == :host && value == nil
        self[ part.to_sym ] = value
      end
    end

    def to_s
      assembler.assemble self
    end

    protected

    def parser
      @parser ||= UrlParser.new
    end

    def assembler
      @assembler ||= UrlAssembler.new
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
earl-0.2.0 lib/earl/url.rb