Module: Imgproxy::OptionsCasters::DrawDetections

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

Overview

Casts ‘draw_detections` processing option

Class Method Summary collapse

Class Method Details

.cast(raw) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/imgproxy/options_casters/draw_detections.rb', line 13

def self.cast(raw)
  # Allow draw_detections to be just a boolean
  return Imgproxy::OptionsCasters::Bool.cast(raw) if [true, false].include?(raw)

  return raw unless raw.is_a?(Hash)
  return unless raw[:draw]

  values = [
    Imgproxy::OptionsCasters::Bool.cast(raw[:draw]),
    *Imgproxy::OptionsCasters::Array.cast(raw[:class_names]),
  ].trim!
  values[0].zero? ? 0 : values
end