module Shrine::Plugins::StoreDimensions::ClassMethods

  1. lib/shrine/plugins/store_dimensions.rb

Methods

Public Instance

  1. dimensions_analyzers
  2. extract_dimensions

Public Instance methods

dimensions_analyzers ()

Returns a hash of built-in dimensions analyzers, where keys are analyzer names and values are #call-able objects which accepts the IO object.

[show source]
# File lib/shrine/plugins/store_dimensions.rb, line 67
def dimensions_analyzers
  @dimensions_analyzers ||= DimensionsAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
    hash.merge!(tool => DimensionsAnalyzer.new(tool).method(:call))
  end
end
extract_dimensions (io)

Determines the dimensions of the IO object by calling the specified analyzer.

[show source]
# File lib/shrine/plugins/store_dimensions.rb, line 53
def extract_dimensions(io)
  analyzer = opts[:dimensions_analyzer]
  analyzer = dimensions_analyzers[analyzer] if analyzer.is_a?(Symbol)
  args = [io, dimensions_analyzers].take(analyzer.arity.abs)

  dimensions = analyzer.call(*args)
  io.rewind

  dimensions
end