Class: Pacing::Error
- Inherits:
-
Object
- Object
- Pacing::Error
- Defined in:
- lib/pacing/error.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#non_business_days ⇒ Object
readonly
Returns the value of attribute non_business_days.
-
#school_plan ⇒ Object
readonly
Returns the value of attribute school_plan.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#summer_holidays ⇒ Object
readonly
Returns the value of attribute summer_holidays.
Instance Method Summary collapse
- #date_within_range ⇒ Object
-
#initialize(school_plan:, date:, non_business_days:, state: :us_tn, mode: :liberal, summer_holidays: []) ⇒ Error
constructor
A new instance of Error.
- #parse_date(date) ⇒ Object
Constructor Details
#initialize(school_plan:, date:, non_business_days:, state: :us_tn, mode: :liberal, summer_holidays: []) ⇒ Error
Returns a new instance of Error.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pacing/error.rb', line 8 def initialize(school_plan:, date:, non_business_days:, state: :us_tn, mode: :liberal, summer_holidays: []) @school_plan = school_plan @non_business_days = non_business_days @date = date @state = state @mode = [:strict, :liberal].include?(mode) ? mode : :liberal raise ArgumentError.new("You must pass in at least one school plan") if school_plan.nil? raise TypeError.new("School plan must be a hash") if school_plan.class != Hash raise ArgumentError.new('You must pass in a date') if date.nil? raise TypeError.new("The date should be formatted as a string in the format mm-dd-yyyy") if date.class != String || !/(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d/.match?(date) raise ArgumentError.new('Date must be within the interval range of the school plan') if !date_within_range non_business_days.each do |non_business_day| raise TypeError.new('"Non business days" dates should be formatted as a string in the format mm-dd-yyyy') if non_business_day.class != String || !/(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d/.match?(non_business_day) end school_plan[:school_plan_services].each do |school_plan_service| raise TypeError.new("School plan type must be a string and cannot be nil") if school_plan_service[:school_plan_type].class != String || school_plan_service[:school_plan_type].nil? raise ArgumentError.new("School plan services start and end dates can not be nil") if school_plan_service[:start_date].nil? || school_plan_service[:end_date].nil? raise TypeError.new("School plan services start and end dates should be formatted as a string in the format mm-dd-yyyy") if school_plan_service[:start_date].class != String || !/(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d/.match?(school_plan_service[:start_date]) raise TypeError.new("School plan services start and end dates should be formatted as a string in the format mm-dd-yyyy") if school_plan_service[:end_date].class != String || !/(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d/.match?(school_plan_service[:end_date]) raise TypeError.new("Type of service must be a string and cannot be nil") if school_plan_service[:type_of_service].class != String || school_plan_service[:type_of_service].nil? raise TypeError.new("Frequency must be an integer and cannot be nil") if school_plan_service[:frequency].class != Integer || school_plan_service[:frequency].nil? raise TypeError.new("Interval must be a string and cannot be nil") if school_plan_service[:interval].class != String || school_plan_service[:interval].nil? raise TypeError.new("Time per session in minutes must be an integer and cannot be nil") if school_plan_service[:time_per_session_in_minutes].class != Integer || school_plan_service[:time_per_session_in_minutes].nil? raise TypeError.new("Completed visits for current interval must be an integer and cannot be nil") if school_plan_service[:completed_visits_for_current_interval].class != Integer || school_plan_service[:completed_visits_for_current_interval].nil? raise TypeError.new("Extra sessions allowable must be an integer and cannot be nil") if school_plan_service[:extra_sessions_allowable].class != Integer || school_plan_service[:extra_sessions_allowable].nil? raise TypeError.new("Interval for extra sessions allowable must be a string and cannot be nil") if school_plan_service[:interval_for_extra_sessions_allowable].class != String || school_plan_service[:interval_for_extra_sessions_allowable].nil? end end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def date @date end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def interval @interval end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def mode @mode end |
#non_business_days ⇒ Object (readonly)
Returns the value of attribute non_business_days.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def non_business_days @non_business_days end |
#school_plan ⇒ Object (readonly)
Returns the value of attribute school_plan.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def school_plan @school_plan end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def state @state end |
#summer_holidays ⇒ Object (readonly)
Returns the value of attribute summer_holidays.
6 7 8 |
# File 'lib/pacing/error.rb', line 6 def summer_holidays @summer_holidays end |
Instance Method Details
#date_within_range ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pacing/error.rb', line 51 def date_within_range valid_range_or_exceptions = false begin @school_plan[:school_plan_services].each do |school_plan_service| if (parse_date(school_plan_service[:start_date]) <= parse_date(@date) && parse_date(@date) <= parse_date(school_plan_service[:end_date])) valid_range_or_exceptions = true end end rescue => exception valid_range_or_exceptions = true end valid_range_or_exceptions end |
#parse_date(date) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/pacing/error.rb', line 67 def parse_date(date) begin Date.strptime(date, '%m-%d-%Y') rescue => exception end end |