class WebReader

Public Class Methods

new(url) click to toggle source
# File lib/genderstat/web_reader.rb, line 6
def initialize url
  @url = clean_up_url url
end

Public Instance Methods

read() click to toggle source
# File lib/genderstat/web_reader.rb, line 10
def read
  begin
    open(@url, :allow_redirections => :safe).read
  rescue Exception => ex
    handle_web_exceptions ex
  end
end

Private Instance Methods

clean_up_url(url) click to toggle source

if the URL is doesn’t match the URI regex, then prepend it with http://

# File lib/genderstat/web_reader.rb, line 28
def clean_up_url url
  if (url =~ URI.regexp).nil?
    "http://#{url}"
  else
    url
  end
end
handle_web_exceptions(ex) click to toggle source
# File lib/genderstat/web_reader.rb, line 19
def handle_web_exceptions ex
  if ex == OpenURI::HTTPError || ex == SocketError
    abort "Could not open: #{url}"
  else
    abort ex.to_s
  end
end