Class: Cats::Core::TransportBid

Inherits:
ApplicationRecord show all
Defined in:
app/models/cats/core/transport_bid.rb

Constant Summary collapse

NEW =
"New".freeze
OPEN =
"Open".freeze
CLOSED =
"Closed".freeze
RANKED =
"Ranked".freeze
WINNERS_DECLARED =
"Winner Declared".freeze
STATUSES =
[NEW, OPEN, CLOSED, RANKED, WINNERS_DECLARED].freeze

Instance Method Summary collapse

Instance Method Details

#closeObject

Raises:

  • (StandardError)


40
41
42
43
44
45
46
47
48
# File 'app/models/cats/core/transport_bid.rb', line 40

def close
  raise(StandardError, "Bid is already closed.") if status == CLOSED

  raise(StandardError, "Bid should first be open.") if status == NEW

  self.status = CLOSED
  save!
  self
end

#openObject

Raises:

  • (StandardError)


30
31
32
33
34
35
36
37
38
# File 'app/models/cats/core/transport_bid.rb', line 30

def open
  raise(StandardError, "Bid is already open.") if status == OPEN

  raise(StandardError, "Bid is empty.") if transport_bid_items.count.zero?

  self.status = OPEN
  save!
  self
end

#quantityObject



50
51
52
# File 'app/models/cats/core/transport_bid.rb', line 50

def quantity
  transport_bid_items.sum(:quantity)
end

#validate_start_date_against_end_dateObject



24
25
26
27
28
# File 'app/models/cats/core/transport_bid.rb', line 24

def validate_start_date_against_end_date
  return unless start_date && end_date

  errors.add(:start_date, "should be before end date.") if start_date >= end_date
end