Class: Shrink::Wrap::Property::Coercion::Enumerable

Inherits:
Object
  • Object
show all
Includes:
Support::TypeCheck
Defined in:
lib/shrink/wrap/property/coercion/enumerable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::TypeCheck

#ensure_callable!, #ensure_type!

Constructor Details

#initialize(enumerable) ⇒ Enumerable

Returns a new instance of Enumerable.



12
13
14
15
# File 'lib/shrink/wrap/property/coercion/enumerable.rb', line 12

def initialize(enumerable)
  ensure_type!(::Enumerable, enumerable)
  self.enumerable = wrap(enumerable.first)
end

Instance Attribute Details

#enumerableObject

Returns the value of attribute enumerable.



10
11
12
# File 'lib/shrink/wrap/property/coercion/enumerable.rb', line 10

def enumerable
  @enumerable
end

Instance Method Details

#coerce(data) ⇒ Object



17
18
19
20
21
# File 'lib/shrink/wrap/property/coercion/enumerable.rb', line 17

def coerce(data)
  return coerce_hash(data) if enumerable.size > 1

  coerce_enumerable(data)
end