Class: SchoolDays::ConfigBase
- Inherits:
-
Object
- Object
- SchoolDays::ConfigBase
- Defined in:
- lib/school_days/config.rb
Overview
controls the behavior of this gem. Currently this gem only supports loading information from a YAML file (TODO: implement programatic ways) … well, you could do it, but I don’t care about that code path yet…
Direct Known Subclasses
Instance Attribute Summary collapse
-
#holiday_exceptions ⇒ Object
Returns the value of attribute holiday_exceptions.
-
#included_day_exceptions ⇒ Object
Returns the value of attribute included_day_exceptions.
-
#school_sessions ⇒ Object
Returns the value of attribute school_sessions.
Instance Method Summary collapse
Instance Attribute Details
#holiday_exceptions ⇒ Object
Returns the value of attribute holiday_exceptions.
12 13 14 |
# File 'lib/school_days/config.rb', line 12 def holiday_exceptions @holiday_exceptions end |
#included_day_exceptions ⇒ Object
Returns the value of attribute included_day_exceptions.
13 14 15 |
# File 'lib/school_days/config.rb', line 13 def included_day_exceptions @included_day_exceptions end |
#school_sessions ⇒ Object
Returns the value of attribute school_sessions.
11 12 13 |
# File 'lib/school_days/config.rb', line 11 def school_sessions @school_sessions end |
Instance Method Details
#load(filename) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/school_days/config.rb', line 21 def load(filename) reset data = YAML::load(File.open(filename)) sessions = data["school_days"]["school_sessions"] self.school_sessions = sessions.collect do |session_name, session_value| if session_value["start_date"].nil? || session_value["end_date"].nil? raise "start_date or end_date is blank for #{session_name} in #{filename}" end {:start_date => Date.parse(session_value["start_date"]), :end_date => Date.parse(session_value["end_date"])} end data["school_days"]["exceptions"]["holidays"].each do |holiday| self.holiday_exceptions << Date.parse(holiday) end data["school_days"]["exceptions"]["included_days"].each do |extra_day| self.included_day_exceptions << Date.parse(extra_day) end end |
#reset ⇒ Object
15 16 17 18 19 |
# File 'lib/school_days/config.rb', line 15 def reset self.school_sessions = {} self.holiday_exceptions = [] self.included_day_exceptions = [] end |
#school_year_end ⇒ Object
51 52 53 54 55 56 |
# File 'lib/school_days/config.rb', line 51 def school_year_end res = self.school_sessions.max do |a, b| a[:end_date] <=> b[:end_date] end res[:end_date] end |
#school_year_start ⇒ Object
44 45 46 47 48 49 |
# File 'lib/school_days/config.rb', line 44 def school_year_start res = self.school_sessions.min do |a, b| a[:start_date] <=> b[:start_date] end res[:start_date] end |