Sha256: 57c217a1b36c7320809ce3fb3b0af06d2398bf5515ed9aadeb8939ee9b678e05

Contents?: true

Size: 462 Bytes

Versions: 6

Compression:

Stored size: 462 Bytes

Contents

# frozen_string_literal: true

module Strict
  module Coercers
    class Array
      attr_reader :element_coercer

      def initialize(element_coercer = nil)
        @element_coercer = element_coercer
      end

      def call(value)
        return value if value.nil? || !value.respond_to?(:to_a)

        array = value.to_a
        return array unless element_coercer

        array.map { |element| element_coercer.call(element) }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strict-1.5.0 lib/strict/coercers/array.rb
strict-1.4.0 lib/strict/coercers/array.rb
strict-1.3.1 lib/strict/coercers/array.rb
strict-1.3.0 lib/strict/coercers/array.rb
strict-1.2.0 lib/strict/coercers/array.rb
strict-1.1.0 lib/strict/coercers/array.rb