Module: Imgproxy::OptionsCasters::Gradient

Defined in:
lib/imgproxy/options_casters/gradient.rb

Overview

Casts ‘gradient` processing option

Constant Summary collapse

CASTER =
Imgproxy::OptionsCasters::Group.new(
  opacity: Imgproxy::OptionsCasters::Float,
  color: Imgproxy::OptionsCasters::String,
  direction: Imgproxy::OptionsCasters::String,
  start: Imgproxy::OptionsCasters::Float,
  stop: Imgproxy::OptionsCasters::Float,
).freeze

Class Method Summary collapse

Class Method Details

.cast(raw) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/imgproxy/options_casters/gradient.rb', line 19

def self.cast(raw)
  # Allow gradient to be just a numeric
  return Imgproxy::OptionsCasters::Float.cast(raw) if raw.is_a?(Numeric)

  return raw unless raw.is_a?(Hash)
  return if raw[:opacity].nil?

  values = CASTER.cast(raw)
  values[0].zero? ? 0 : values
end