Class: Externals::Grab::Order

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/externals/grab/order.rb

Overview

typed: ignore

Schema Information

Table name: externals_grab_orders

id             :bigint           not null, primary key
order_ref      :string(191)
price          :string(191)
price_cents    :integer          default(0), not null
price_currency :string(191)      default("THB")
status         :string(191)
created_at     :datetime         not null
updated_at     :datetime         not null

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/externals/grab/order.rb', line 24

def complete?
  status_as_constant == Driver::DELIVERED.to_s
end

#status_as_constantObject

Returns String.

Returns:

  • String



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/externals/grab/order.rb', line 29

def status_as_constant
  case status
  when Driver::GRAB_FINDING_DRIVER
    'Driver::FINDING_DRIVER'
  when Driver::GRAB_ON_THE_WAY_TO_RESTAURANT, 'PICKING_UP'
    'Driver::ON_THE_WAY_TO_RESTAURANT'
  when Driver::GRAB_CANCELLED
    'Driver::CANCELLED'
  when Driver::GRAB_IN_DELIVERY, 'IN_DELIVERY'
    'Driver::PICKED_UP'
  when Driver::GRAB_FAILED
    'Driver::REJECTED'
  when Driver::GRAB_DELIVERED, 'COMPLETED'
    'Driver::DELIVERED'
  else
    APMErrorHandler.report('unknown status', order: attributes.to_h, status: status)
    'Driver::FINDING_DRIVER'
  end
end