Class: SpreeCmCommissioner::ServiceCalendar

Inherits:
Base
  • Object
show all
Includes:
ServiceCalendarType
Defined in:
app/models/spree_cm_commissioner/service_calendar.rb

Constant Summary collapse

EXCEPTION_RULE_JSON_SCHEMA =
Pathname.new("#{COMMISSIONER_ROOT}/config/schemas/service_calendar_exception_rule.json")

Constants included from ServiceCalendarType

SpreeCmCommissioner::ServiceCalendarType::SERVICE_TYPES

Instance Method Summary collapse

Instance Method Details

#get_exception_rule(date) ⇒ Object



28
29
30
31
32
# File 'app/models/spree_cm_commissioner/service_calendar.rb', line 28

def get_exception_rule(date)
  exception_rules.find do |rule|
    rule['from'].to_date <= date && date <= rule['to'].to_date
  end
end

#service_available?(date) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'app/models/spree_cm_commissioner/service_calendar.rb', line 20

def service_available?(date)
  exception_rule = get_exception_rule(date)
  # return bases on exception_rule first
  return exception_rule['type'] == 'inclusion' if exception_rule.present?

  service_started?(date) && in_weekly_service?(date)
end