class EnvatoOptimiser::TotalImageWeightCheck

Public Class Methods

new(image_urls) click to toggle source

Initialize a total image weight check.

@param image_urls [Array] Image URLs that you would like to fetch the

total image weight for.

@return [Nothing].

# File lib/envato_optimiser/checks/total_image_weight_check.rb, line 9
def initialize(image_urls)
  @total_image_weight = 0
  get_total_image_weight(image_urls)
end

Public Instance Methods

to_h() click to toggle source

Format the results into a usable Hash.

@return [Hash] `:total_image_weight` is the total image size in bytes.

# File lib/envato_optimiser/checks/total_image_weight_check.rb, line 17
def to_h
  {
    :total_image_weight => @total_image_weight
  }
end

Private Instance Methods

get_total_image_weight(image_urls) click to toggle source
# File lib/envato_optimiser/checks/total_image_weight_check.rb, line 25
def get_total_image_weight(image_urls)
  image_urls.each do |image|
    response = Net::HTTP.get_response(URI.parse(image))
    @total_image_weight += response.content_length
  end
end