Class: Gorillib::Factory::EnumerableFactory

Inherits:
ConvertingFactory show all
Defined in:
lib/gorillib/factories.rb

Direct Known Subclasses

ArrayFactory, HashFactory, SetFactory

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConvertingFactory

#receive

Methods inherited from BaseFactory

blankish?, native?, #receive, #typename, typename

Constructor Details

#initialize(options = {}) ⇒ EnumerableFactory

Returns a new instance of EnumerableFactory.



486
487
488
489
490
# File 'lib/gorillib/factories.rb', line 486

def initialize(options={})
  @items_factory = Gorillib::Factory( options.delete(:items){ :identical } )
  redefine(:empty_product, options.delete(:empty_product)) if options.has_key?(:empty_product)
  super(options)
end

Instance Attribute Details

#items_factoryObject (readonly)

[#receive] factory for converting items



484
485
486
# File 'lib/gorillib/factories.rb', line 484

def items_factory
  @items_factory
end

Instance Method Details

#blankish?(obj) ⇒ Boolean

Returns:

  • (Boolean)


492
# File 'lib/gorillib/factories.rb', line 492

def blankish?(obj)    obj.nil? ; end

#convert(obj) ⇒ Object



499
500
501
502
503
504
505
# File 'lib/gorillib/factories.rb', line 499

def convert(obj)
  clxn = empty_product
  obj.each do |val|
    clxn << items_factory.receive(val)
  end
  clxn
end

#empty_productObject



495
496
497
# File 'lib/gorillib/factories.rb', line 495

def empty_product
  @product.new
end

#native?(obj) ⇒ Boolean

Returns:

  • (Boolean)


493
# File 'lib/gorillib/factories.rb', line 493

def native?(obj)      false    ; end