module Spok::Calendars
Internal: Module responsible for loading and collecting calendar definitions from YAML files.
Public Class Methods
add(name, path)
click to toggle source
Public: Add a new calendar.
name - A String or Symbol with the name of the calendar. path - A String with the full path for the calendar YAML file.
Returns nothing.
# File lib/spok/calendars.rb, line 16 def self.add(name, path) @@calendars[name.to_s] = load(name, path) end
get(name)
click to toggle source
Public: Get a calendar.
name - A String or Symbol with the name of the calendar.
Raises a `KeyError` if the calender does not exists. Returns a `Set`.
# File lib/spok/calendars.rb, line 26 def self.get(name) @@calendars.fetch(name.to_s) { raise KeyError, "Calendar not found: #{name}" } end
preload()
click to toggle source
Internal: Preloads existing calendars into memory.
Returns nothing.
# File lib/spok/calendars.rb, line 33 def self.preload Dir[File.expand_path("config/*.yml", __dir__)].each do |path| name = File.basename(path, '.yml') add(name, path) end end
Private Class Methods
load(name, path)
click to toggle source
# File lib/spok/calendars.rb, line 40 def self.load(name, path) dates = YAML.safe_load(File.read(path), [Date]) Set.new(dates[name.to_s]) end