Class: FaviconExtractor::ChoosesLargestImage

Inherits:
Object
  • Object
show all
Defined in:
lib/favicon_extractor/chooses_largest_image.rb

Class Method Summary collapse

Class Method Details

.choose(images) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/favicon_extractor/chooses_largest_image.rb', line 3

def self.choose(images)
  return nil unless images.any?

  images.map do |icon|
    {source: icon, size: FastImage.size(icon)}
  end
    .select { |h| h[:size] }
    .max_by { |h| h[:size][0] * h[:size][1] }&.fetch(:source)
end