Sha256: 9d06b082a257024a56e1fdb27b9f256eaa6f858bcdc8859226327d357f6270c6

Contents?: true

Size: 586 Bytes

Versions: 4

Compression:

Stored size: 586 Bytes

Contents

module Rentvine
  class RentvineModel < OpenStruct
    def initialize(data = {})
      super(data)
    end

    def to_rentvine_hash
      data_hash = to_h

      # Remove custom appends from the hash
      meta&.dig(:appends)&.each { |key| data_hash.delete(key) }
      data_hash.delete(:meta)

      data_hash = data_hash.to_camelback_keys

      data_hash.keys.each do |key|
        next if (key.to_s =~ /Id$/).nil?

        new_key = key.to_s.gsub(/Id$/, 'ID')
        data_hash[new_key.to_sym] = data_hash.delete(key)
      end

      data_hash.to_camelback_keys
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rentvine-0.3.1 lib/rentvine/model/rentvine_model.rb
rentvine-0.3.0 lib/rentvine/model/rentvine_model.rb
rentvine-0.2.0 lib/rentvine/model/rentvine_model.rb
rentvine-0.1.0 lib/rentvine/model/rentvine_model.rb