Class: Gorillib::Factory::HashFactory
- Inherits:
-
EnumerableFactory
- Object
- BaseFactory
- ConvertingFactory
- EnumerableFactory
- Gorillib::Factory::HashFactory
- Defined in:
- lib/gorillib/factories.rb
Instance Attribute Summary collapse
-
#keys_factory ⇒ Object
readonly
[#receive] factory for converting keys.
Attributes inherited from EnumerableFactory
Instance Method Summary collapse
- #convert(obj) ⇒ Object
-
#initialize(options = {}) ⇒ HashFactory
constructor
A new instance of HashFactory.
Methods inherited from EnumerableFactory
#blankish?, #empty_product, #native?
Methods inherited from ConvertingFactory
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(={}) @keys_factory = Gorillib::Factory( .delete(:keys){ Gorillib::Factory(:identical) } ) super() end |
Instance Attribute Details
#keys_factory ⇒ Object (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 |