class ImagePaths

Main gem class

Constants

VERSION

Public Class Methods

at(page_path) click to toggle source
# File lib/image_paths.rb, line 9
def self.at(page_path)
  begin
    return collect_paths(page_path) if path_correct?(page_path)
  rescue => e
    puts "StandardError: #{e}"
    return []
  end
  []
end
collect_paths(page_path) click to toggle source
# File lib/image_paths.rb, line 49
def self.collect_paths(page_path)
  links = []
  Nokogiri::HTML(open(page_path)).css('img').select { |link| links << link.attr('src') }
  links
end
path_correct?(page_path) click to toggle source
# File lib/image_paths.rb, line 19
def self.path_correct?(page_path)
  uri_ok?(page_path) && response_ok?(page_path)
end
response_ok?(page_path) click to toggle source

response.body, .code, .message, .headers.inspect

# File lib/image_paths.rb, line 32
def self.response_ok?(page_path)
  begin
    response = HTTParty.get(page_path)
    if response.code.to_i >= 400
      puts "Error: bad response: response.code = #{response.code}"
      return false
    end
  rescue HTTParty::Error
    puts 'HTTParty::Error: bad response. HTTParty::Error'
    return false
  rescue StandardError
    puts 'StandardError: bad response'
    return false
  end
  true
end
uri_ok?(page_path) click to toggle source
# File lib/image_paths.rb, line 23
def self.uri_ok?(page_path)
  unless page_path =~ /\A#{URI.regexp(%w(http https))}\z/
    puts 'Error: bad uri'
    return false
  end
  true
end