class EnvatoOptimiser::Item
Public Class Methods
new(item_url)
click to toggle source
Initialize a new item page.
@return [Nothing]
# File lib/envato_optimiser/item.rb, line 10 def initialize(item_url) uri = URI.parse(item_url) response = Net::HTTP.get_response(uri) @document = Nokogiri::HTML(response.body) @image_urls = image_urls end
Public Instance Methods
check!(skip_image_status_check: false, skip_total_image_weight_check: false)
click to toggle source
Run checks against a specific item page.
@param skip_image_status_check [Boolean] Used for determining whether or
not the image HTTP response status checks should be run.
@param skip_total_image_weight_check [Boolean] Determine whether or not
you would like to calculate the total image weight generated by the item page.
@return [Hash] Consolidated list of the checks output.
# File lib/envato_optimiser/item.rb, line 26 def check!(skip_image_status_check: false, skip_total_image_weight_check: false) reports = [] reports << EnvatoOptimiser::ImageResponseStatusCodeCheck.new(@image_urls).to_h unless skip_image_status_check reports << EnvatoOptimiser::TotalImageWeightCheck.new(@image_urls).to_h unless skip_total_image_weight_check reports.inject(&:merge) end
Private Instance Methods
image_urls()
click to toggle source
Gather all the image URLs.
Loops over the document output and collects all of the image source values
within the defined CSS div where user input is declared.
@return [Array] All the images found in the requested document.
# File lib/envato_optimiser/item.rb, line 43 def image_urls images = [] @document.css('.user-html img').map do |image| images << image.attributes['src'].value end # Don't choke on protocol relative URL's. images.collect { |image| image.gsub(%r{^//}, 'https://') } end