class Arbetsformedlingen::Schedule
Constants
- DURATION_MAP
Public Class Methods
new(hash)
click to toggle source
Calls superclass method
Arbetsformedlingen::Model::new
# File lib/arbetsformedlingen/models/schedule.rb, line 30 def initialize(hash) data = hash.dup duration_code = duration_code(data[:start_date], data[:end_date]) data[:position_duration_code] = duration_code data[:full_time] = duration_code == -1 super(ScheduleSchema.call(data)) end
Private Instance Methods
duration_code(start_date, end_date)
click to toggle source
# File lib/arbetsformedlingen/models/schedule.rb, line 40 def duration_code(start_date, end_date) return DURATION_MAP.fetch(:regular) if end_date.nil? days = end_date - start_date return DURATION_MAP.fetch(:from_0_days_to_10_days) if days <= 10 return DURATION_MAP.fetch(:from_11_days_to_3_months) if days > 10 && days < 92 return DURATION_MAP.fetch(:from_june_to_august) if summer_job?(start_date, end_date) return DURATION_MAP.fetch(:from_3_months_to_6_months) if days >= 92 && days < 183 DURATION_MAP.fetch(:from_6_months_to_longer) end
summer_job?(start_date, end_date)
click to toggle source
# File lib/arbetsformedlingen/models/schedule.rb, line 53 def summer_job?(start_date, end_date) start_date.month == 6 && start_date.day == 1 && end_date.month == 8 && end_date.day == 31 end