Sha256: f43aa50e4a39bc436f91de131f6dd7846967cf1679625d3dad3816d1feb20681

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

## -*- Ruby -*-
## URLopen
## 1999 by yoshidam
##
## TODO: This module should be writen by Ruby instead of wget/lynx.

module WGET
  PARAM = {
    'wget' => nil,
    'opts' => nil,
    'http_proxy' => nil,
    'ftp_proxy' => nil
  }

  def open(url, *rest)
      raise TypeError.new("wrong argument type #{url.inspect}" +
                          " (expected String)") if url.class != String

    if url =~ /^\/|^\./ || (url !~ /^http:|^ftp:/ && FileTest.exist?(url))
      File::open(url, *rest)
    else
      ENV['http_proxy'] = PARAM['http_proxy'] if PARAM['http_proxy']
      ENV['ftp_proxy'] = PARAM['ftp_proxy'] if PARAM['ftp_proxy']
      IO::popen(PARAM['wget'] + ' ' + PARAM['opts'] + ' ' + url)
    end
  end
  module_function :open
end

[ '/usr/local/bin/wget', '/usr/bin/wget',
  '/usr/local/bin/lynx', '/usr/bin/lynx',
  '/usr/local/bin/lwp-request', '/usr/bin/lwp-request' ].each do |p|
  if FileTest.executable?(p)
    WGET::PARAM['wget'] = p
    case p
    when /wget$/
      WGET::PARAM['opts'] = '-q -O -'
    when /lynx$/
      WGET::PARAM['opts'] = '-source'
    when /lwp-request$/
      WGET::PARAM['opts'] = '-m GET'
    end
    break
  end
end

raise "wget not found" if !WGET::PARAM['wget']

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mame-xmlparser-0.6.81.1 lib/wget.rb
xmlparser-0.7.2.1 lib/wget.rb
xmlparser-0.6.81 lib/wget.rb