class GouvCalendarCompilator::DataCompilator

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

Public Class Methods

fill_operating_days(calendar) click to toggle source

Fill in the gaps in school holidays + national days off calendar with operatiog periods

# File lib/gouv_calendar_compilator/data_compilator.rb, line 39
def self.fill_operating_days(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
new() click to toggle source

Initializer for Data Compiler class.

# 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
sort_calendar_data(calendar) click to toggle source

Sorts calendar data by date

# 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

Public Instance Methods

compile() click to toggle source

This is the method you want to call to compile the sources into a proper dataset. It returns a ruby Array of Hashes

# 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.fill_operating_days(ndo_and_sh_data)
end