Class: Auctify::SalesPack
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Auctify::SalesPack
- Includes:
- Folio::FriendlyId, Folio::HasAttachments, Folio::Positionable, Folio::Publishable::Basic, Folio::Sitemap::Base
- Defined in:
- app/models/auctify/sales_pack.rb
Instance Method Summary collapse
- #dates_to_label ⇒ Object
- #shift_sales_by_minutes!(shift_in_minutes) ⇒ Object
- #time_frame ⇒ Object
- #to_label ⇒ Object
Instance Method Details
#dates_to_label ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/auctify/sales_pack.rb', line 47 def dates_to_label return "" unless start_date && end_date date_strings = [] if start_date.year == end_date.year if start_date.month == end_date.month # all inside same month date_strings << start_date.strftime("%-d.") else # all inside same year date_strings << start_date.strftime("%-d. %-m.") end else # crossing years border date_strings << start_date.strftime("%-d. %-m. %Y") end date_strings << end_date.strftime("%-d. %-m. %Y") date_strings.join(" – ") end |
#shift_sales_by_minutes!(shift_in_minutes) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/auctify/sales_pack.rb', line 68 def shift_sales_by_minutes!(shift_in_minutes) self.transaction do sales.each do |sale| sale.update!(ends_at: sale.ends_at + shift_in_minutes.minutes) validate_sale_ends_in_time_frame(sale) raise ActiveRecord::RecordInvalid if errors[:sales].present? end end sales.reload end |
#time_frame ⇒ Object
80 81 82 |
# File 'app/models/auctify/sales_pack.rb', line 80 def time_frame (start_date.to_time..(end_date.to_time + 1.day)) end |
#to_label ⇒ Object
43 44 45 |
# File 'app/models/auctify/sales_pack.rb', line 43 def to_label title end |