Sha256: 26ba1a8364ed42a0647098063b77b70e0a912ca05f8c338d88c3cd744879aee8

Contents?: true

Size: 416 Bytes

Versions: 12

Compression:

Stored size: 416 Bytes

Contents

module Coprl::Presenters::WebClient::Helpers
  module TransformHash
    def to_hash(ostruct_or_hash)
      {}.tap do |h|
        ostruct_or_hash.to_h.each {|key, value| h[key.to_sym] = transform(value)}
      end
    end

    def transform(thing)
      case thing
      when OpenStruct
        to_hash(thing)
      when Array
        thing.map {|v| transform(v)}
      else
        thing
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.11 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.10 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.9 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.8 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.7 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.6 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.5 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.4 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.3 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.2 lib/coprl/presenters/web_client/helpers/transform_hash.rb
coprl-3.0.0.beta.1 lib/coprl/presenters/web_client/helpers/transform_hash.rb