Class: Rentvine::RentvineModel

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rentvine/model/rentvine_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ RentvineModel

Returns a new instance of RentvineModel.



3
4
5
# File 'lib/rentvine/model/rentvine_model.rb', line 3

def initialize(data = {})
  super(data)
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rentvine/model/rentvine_model.rb', line 7

def error?
  false
end

#to_rentvine_hashObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rentvine/model/rentvine_model.rb', line 11

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