Module: Spok::Calendars
- Defined in:
- lib/spok/calendars.rb
Overview
Internal: Module responsible for loading and collecting calendar definitions from YAML files.
Constant Summary collapse
- @@calendars =
{}
Class Method Summary collapse
-
.add(name, path) ⇒ Object
Public: Add a new calendar.
-
.get(name) ⇒ Object
Public: Get a calendar.
-
.preload ⇒ Object
Internal: Preloads existing calendars into memory.
Class Method Details
.add(name, path) ⇒ Object
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.
16 17 18 |
# File 'lib/spok/calendars.rb', line 16 def self.add(name, path) @@calendars[name.to_s] = load(name, path) end |
.get(name) ⇒ Object
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`.
26 27 28 |
# File 'lib/spok/calendars.rb', line 26 def self.get(name) @@calendars.fetch(name.to_s) { raise KeyError, "Calendar not found: #{name}" } end |
.preload ⇒ Object
Internal: Preloads existing calendars into memory.
Returns nothing.
33 34 35 36 37 38 |
# File 'lib/spok/calendars.rb', line 33 def self.preload Dir[File.("config/*.yml", __dir__)].each do |path| name = File.basename(path, '.yml') add(name, path) end end |