Class: SpreeCmCommissioner::Promotion::Rules::Weekend

Inherits:
Date
  • Object
show all
Defined in:
app/models/spree_cm_commissioner/promotion/rules/weekend.rb

Constant Summary collapse

DAYS_INTO_WEEK =
DateAndTime::Calculations::DAYS_INTO_WEEK

Constants inherited from Date

Date::MATCH_POLICIES

Instance Method Summary collapse

Methods inherited from Date

#actionable?, #applicable?, #eligible?, #line_item_eligible?

Instance Method Details

#date_eligible?(date) ⇒ Boolean

override

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/models/spree_cm_commissioner/promotion/rules/weekend.rb', line 18

def date_eligible?(date)
  return false if exception?(date)

  weekend?(date)
end

#exception?(date) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'app/models/spree_cm_commissioner/promotion/rules/weekend.rb', line 28

def exception?(date)
  return false if preferred_exception_dates.blank?

  preferred_exception_dates.any? do |exception|
    match?(exception, date)
  end
end

#sort_exception_datesObject



13
14
15
# File 'app/models/spree_cm_commissioner/promotion/rules/weekend.rb', line 13

def sort_exception_dates
  self.preferred_exception_dates = preferred_exception_dates.sort_by { |obj| JSON.parse(obj)['start_date'] }
end

#weekend?(date) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/spree_cm_commissioner/promotion/rules/weekend.rb', line 24

def weekend?(date)
  preferred_weekend_days.include?(date.wday.to_s)
end