module PhotoCook::Utils

Public Class Methods

call_block_with_floating_arguments(callable, args) click to toggle source
# File lib/photo-cook/utils.rb, line 19
def call_block_with_floating_arguments(callable, args)
  arity         = callable.arity
  resized_args  = arity < 0 ? args : args[0...arity]
  callable.call(*resized_args)
end
format_size(bytes, precision = 2) click to toggle source
# File lib/photo-cook/utils.rb, line 7
def format_size(bytes, precision = 2)
  if bytes >= 1_000_000_000.0
    "#{(bytes / 1_000_000_000.0).round(precision)} GB"

  elsif bytes >= 1_000_000.0
    "#{(bytes / 1_000_000.0).round(precision)} MB"

  else
    "#{(bytes / 1_000.0).round(precision)} KB"
  end
end
measure() { || ... } click to toggle source
# File lib/photo-cook/utils.rb, line 65
def measure
  started  = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
  returned = yield
  finished = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
  [returned, finished - started]
end