Class: Gorillib::Factory::HashFactory

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



518
519
520
521
# File 'lib/gorillib/factories.rb', line 518

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



515
516
517
# File 'lib/gorillib/factories.rb', line 515

def keys_factory
  @keys_factory
end

Instance Method Details

#convert(obj) ⇒ Object



523
524
525
526
527
528
529
# File 'lib/gorillib/factories.rb', line 523

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