Class: Comee::Core::Price
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Comee::Core::Price
- Defined in:
- app/models/comee/core/price.rb
Direct Known Subclasses
Instance Method Summary collapse
- #approve ⇒ Object
- #approved? ⇒ Boolean
- #compute_status ⇒ Object
- #current? ⇒ Boolean
- #draft? ⇒ Boolean
- #future? ⇒ Boolean
- #past? ⇒ Boolean
- #validate_price_validity_dates ⇒ Object
Instance Method Details
#approve ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/models/comee/core/price.rb', line 45 def approve if Price.price_statuses[price_status] == Price.price_statuses[:approved] raise(StandardError, "Price status is already in approved state.") end self.price_status = Price.price_statuses[:approved] save! self end |
#approved? ⇒ Boolean
30 31 32 |
# File 'app/models/comee/core/price.rb', line 30 def approved? Price.price_statuses[price_status] == Price.price_statuses[:approved] end |
#compute_status ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/comee/core/price.rb', line 34 def compute_status period = Period.new(valid_from, valid_to) if period.past? self.status = Price.statuses[:past] elsif period.current? self.status = Price.statuses[:current] elsif period.future? self.status = Price.statuses[:future] end end |
#current? ⇒ Boolean
59 60 61 |
# File 'app/models/comee/core/price.rb', line 59 def current? Price.statuses[status] == Price.statuses[:current] end |
#draft? ⇒ Boolean
26 27 28 |
# File 'app/models/comee/core/price.rb', line 26 def draft? Price.price_statuses[price_status] == Price.price_statuses[:draft] end |
#future? ⇒ Boolean
63 64 65 |
# File 'app/models/comee/core/price.rb', line 63 def future? Price.statuses[status] == Price.statuses[:future] end |
#past? ⇒ Boolean
55 56 57 |
# File 'app/models/comee/core/price.rb', line 55 def past? Price.statuses[status] == Price.statuses[:past] end |
#validate_price_validity_dates ⇒ Object
19 20 21 22 23 24 |
# File 'app/models/comee/core/price.rb', line 19 def validate_price_validity_dates return unless valid_from && valid_to period = Period.new(valid_from, valid_to) errors.add(:base, "Price validity date range is not correct.") unless period.valid? end |