Class: Gorillib::Factory::HashFactory

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

Instance Attribute Summary collapse

Attributes inherited from EnumerableFactory

#items_factory

Instance Method Summary collapse

Methods inherited from EnumerableFactory

#blankish?, #empty_product, #native?

Methods inherited from ConvertingFactory

#receive

Methods inherited from BaseFactory

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

Constructor Details

#initialize(options = {}) ⇒ HashFactory

Returns a new instance of HashFactory.



510
511
512
513
# File 'lib/gorillib/model/factories.rb', line 510

def initialize(options={})
  @keys_factory = Gorillib::Factory( options.delete(:keys){ Gorillib::Factory(:identical) } )
  super(options)
end

Instance Attribute Details

#keys_factoryObject (readonly)

#receive

factory for converting keys



507
508
509
# File 'lib/gorillib/model/factories.rb', line 507

def keys_factory
  @keys_factory
end

Instance Method Details

#convert(obj) ⇒ Object



515
516
517
518
519
520
521
# File 'lib/gorillib/model/factories.rb', line 515

def convert(obj)
  hsh = empty_product
  obj.each_pair do |key, val|
    hsh[keys_factory.receive(key)] = items_factory.receive(val)
  end
  hsh
end