Sha256: add05e0180fdb468b4c0a4ef6456db94ae270afb66981ef6d75ca92d234eca0c
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
# frozen_string_literal: true module Arbetsformedlingen ScheduleSchema = Dry::Validation.Params do configure do config.type_specs = true config.messages_file = File.expand_path('../../../config/locales/errors.yml', __dir__) predicates(Predicates) end required(:summary, Types::StrippedString).filled required(:full_time, Types::Strict::Bool).filled required(:position_duration_code, Types::PositionDuration).filled required(:start_date, Types::StrippedString).filled(:yyyy_mm_dd?) optional(:end_date, Types::StrippedString) end class Schedule < Model DURATION_MAP = { regular: -1, from_0_days_to_10_days: 8, from_11_days_to_3_months: 7, from_june_to_august: 4, # summer months (June to August) from_3_months_to_6_months: 3, from_6_months_to_longer: 2, }.freeze 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 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 def summer_job?(start_date, end_date) start_date.month == 6 && start_date.day == 1 && end_date.month == 8 && end_date.day == 31 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
arbetsformedlingen-0.7.0 | lib/arbetsformedlingen/models/schedule.rb |
arbetsformedlingen-0.6.0 | lib/arbetsformedlingen/models/schedule.rb |