Sha256: 41d11b63a2fb3587938bfd07c6c816cc79664c6e6b7ab945a64c86733407061f

Contents?: true

Size: 770 Bytes

Versions: 26

Compression:

Stored size: 770 Bytes

Contents

module MotionPrime
  module HasNormalizer
    def normalize_options(unordered_options, receiver = nil, order = nil)
      options = if order
        Hash[unordered_options.sort_by { |k,v| order.index(k.to_s).to_i }]
      else
        unordered_options
      end

      options.each do |key, option|
        unordered_options[key] = normalize_object(option, receiver)
      end
    end

    def normalize_object(object, receiver = nil)
      receiver ||= self
      if object.is_a?(Proc)
        receiver.send(:instance_exec, self, &object)
      elsif object.is_a?(Hash)
        object.inject({}) do |result, (key, nested_object)|
          result.merge(key => normalize_object(nested_object, receiver))
        end
      else
        object
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
motion-prime-0.9.5 motion-prime/helpers/has_normalizer.rb
motion-prime-0.9.4 motion-prime/helpers/has_normalizer.rb
motion-prime-0.9.3 motion-prime/helpers/has_normalizer.rb
motion-prime-0.9.2 motion-prime/helpers/has_normalizer.rb
motion-prime-0.9.1 motion-prime/helpers/has_normalizer.rb
motion-prime-0.9.0 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.12 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.11 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.10 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.9 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.8 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.7 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.6 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.5 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.4 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.3 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.2 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.1 motion-prime/helpers/has_normalizer.rb
motion-prime-0.8.0 motion-prime/helpers/has_normalizer.rb
motion-prime-0.7.2 motion-prime/helpers/has_normalizer.rb