class FeedTorrents::Feed::MagnetURI

Public Class Methods

new(uri) click to toggle source
# File lib/feed_torrents/feed/magnet-uri.rb, line 9
def initialize(uri)
  raise ArgumentError, 'bad argument (expected magnet URI)' unless uri =~ /^magnet:\?/

  uri = CGI.unescapeHTML(uri)

  scheme, params = uri.split('?', 2)

  @params = {}.tap do |param|
    CGI.parse(URI.decode(params)).each do |name, value|
      name  = name.to_sym
      value = (value.size == 1 ? value.first : value)

      param[name] = value
    end
  end

  @info_hash = @params[:xt].split(':').last
end

Public Instance Methods