Sha256: 777485415cad7353d8eef55031525f57f776e978afdd6ceee84adacfa228907c

Contents?: true

Size: 853 Bytes

Versions: 10

Compression:

Stored size: 853 Bytes

Contents

module Iyzi
  class Utils
    class << self
      def hash_to_properties(hash)
        newprops = {}
        hash.each_pair { |k, v| newprops[k.to_s.camelize(:lower)] = convert_to_prop(v) }
        newprops
      end

      def properties_to_hash(props)
        hash = HashWithIndifferentAccess.new
        props.each_pair { |k, v| hash[k.underscore] = convert_to_hash(v) }
        hash
      end

      def convert_to_prop(v)
        if v.is_a?(Hash)
          hash_to_properties(v)
        elsif v.is_a?(Array)
          v.collect { |item| hash_to_properties(item) }
        else
          v
        end
      end

      def convert_to_hash(v)
        if v.is_a?(Hash)
          properties_to_hash(v)
        elsif v.is_a?(Array)
          v.collect { |item| properties_to_hash(item) }
        else
          v
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iyzi-0.8.1 lib/iyzi/utils.rb
iyzi-0.8.0 lib/iyzi/utils.rb
iyzi-0.7.0 lib/iyzi/utils.rb
iyzi-0.6.0 lib/iyzi/utils.rb
iyzi-0.5.0 lib/iyzi/utils.rb
iyzi-0.4.0 lib/iyzi/utils.rb
iyzi-0.3.0 lib/iyzi/utils.rb
iyzi-0.2.0 lib/iyzi/utils.rb
iyzi-0.1.0 lib/iyzi/utils.rb
iyzi-0.0.1 lib/iyzi/utils.rb