Sha256: 82c96b2a7274c93b3bca4f5dca0dd00474a0d2483b44ba7f97de10be3ab675c0

Contents?: true

Size: 574 Bytes

Versions: 1

Compression:

Stored size: 574 Bytes

Contents

require 'struct_trans/hash'

module StructTrans
  module_function

  def transform kind, struct, schema
    case schema
    when Symbol
      struct.public_send(schema)
    when Array
      schema.map do |key|
        transform(kind, struct, key)
      end
    when Hash
      schema.inject(public_send("construct_#{kind}")) do |box, (key, value)|
        public_send("write_#{kind}",
          box, key, transform(kind, struct.public_send(key), value))
        box
      end
    else
      raise TypeError.new("Unknown type: #{schema.class}: #{schema}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
struct_trans-0.5.0 lib/struct_trans.rb