Sha256: f9d0ce94807c399c527785f21b81a6d4e1db36b2eed26b625bc29d3deef5e9c1

Contents?: true

Size: 365 Bytes

Versions: 1

Compression:

Stored size: 365 Bytes

Contents

module Id
  class Hashifier

    def initialize(data)
      @data = data
    end

    def hashify
      Hash[data.map { |k, v| [ k.to_s, as_data(v) ] }]
    end

    private

    def as_data(v)
      case v
      when Id::Model then v.data
      when Array then v.first.is_a?(Id::Model) ? v.map(&:data) : v
      else v end
    end

    attr_reader :data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
id-0.0.6 lib/id/hashifier.rb