Class: GouvCalendarCompilator::DataCompilator
- Inherits:
-
Object
- Object
- GouvCalendarCompilator::DataCompilator
- Defined in:
- lib/gouv_calendar_compilator/data_compilator.rb
Overview
This is the Data Compilator Object for the Gouv Data Compilator gem It manages the compilation of different data sources and compile them into a new, properly formatted one
Class Method Summary collapse
-
.fill_operating_days(calendar) ⇒ Object
Fill in the gaps in school holidays + national days off calendar with operatiog periods.
-
.sort_calendar_data(calendar) ⇒ Object
Sorts calendar data by date.
Instance Method Summary collapse
-
#compile ⇒ Object
This is the method you want to call to compile the sources into a proper dataset.
-
#initialize ⇒ DataCompilator
constructor
Initializer for Data Compiler class.
Constructor Details
#initialize ⇒ DataCompilator
Initializer for Data Compiler class.
17 18 19 20 |
# File 'lib/gouv_calendar_compilator/data_compilator.rb', line 17 def initialize @sh_data_compiler = ::GouvCalendarCompilator::France::SchoolHolidaysDataCompilator.new @ndo_data_compiler = ::GouvCalendarCompilator::France::NationalDaysOffDataCompilator.new end |
Class Method Details
.fill_operating_days(calendar) ⇒ Object
Fill in the gaps in school holidays + national days off calendar with operatiog periods
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gouv_calendar_compilator/data_compilator.rb', line 39 def self.(calendar) calendar = sort_calendar_data(calendar) calendar.each_key do |zone| new_entries = [] calendar[zone].each_with_index do |vacation_period, index| current_end_date = ::Date.parse(vacation_period[:end]) if calendar[zone][index + 1].nil? if (current_end_date...::GouvCalendarCompilator::DATETIME_END).count > 1 new_entries.push( { start: current_end_date.to_date.to_s, end: (::GouvCalendarCompilator::DATETIME_END + 1).to_date.to_s, coefficient: ::GouvCalendarCompilator::OPERATING_DAY } ) end else next_start_date = ::Date.parse(calendar[zone][index + 1][:start]) if (current_end_date...next_start_date).count >= 1 new_entries.push( { start: current_end_date.to_date.to_s, end: next_start_date.to_date.to_s, coefficient: ::GouvCalendarCompilator::OPERATING_DAY } ) end end end calendar[zone] += new_entries end sort_calendar_data(calendar) end |
.sort_calendar_data(calendar) ⇒ Object
Sorts calendar data by date
31 32 33 34 35 36 |
# File 'lib/gouv_calendar_compilator/data_compilator.rb', line 31 def self.sort_calendar_data(calendar) calendar.each_key do |zone_name| calendar[zone_name].sort_by! { |rec| ::Date.parse(rec[:start]) } end calendar end |
Instance Method Details
#compile ⇒ Object
This is the method you want to call to compile the sources into a proper dataset. It returns a ruby Array of Hashes
24 25 26 27 28 |
# File 'lib/gouv_calendar_compilator/data_compilator.rb', line 24 def compile sh_calendar_data = @sh_data_compiler.compile ndo_and_sh_data = self.class.sort_calendar_data(@ndo_data_compiler.compile(sh_calendar_data)) self.class.(ndo_and_sh_data) end |