Class: Gorillib::Factory::EnumerableFactory

Inherits:
ConvertingFactory show all
Defined in:
lib/gorillib/model/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.



478
479
480
481
482
# File 'lib/gorillib/model/factories.rb', line 478

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



476
477
478
# File 'lib/gorillib/model/factories.rb', line 476

def items_factory
  @items_factory
end

Instance Method Details

#blankish?(obj) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#convert(obj) ⇒ Object



491
492
493
494
495
496
497
# File 'lib/gorillib/model/factories.rb', line 491

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

#empty_productObject



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

def empty_product
  @product.new
end

#native?(obj) ⇒ Boolean

Returns:

  • (Boolean)


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

def native?(obj)      false    ; end