Class: CalendariumRomanum::SanctoraleFactory
- Inherits:
-
Object
- Object
- CalendariumRomanum::SanctoraleFactory
- Defined in:
- lib/calendarium-romanum/sanctorale_factory.rb
Overview
Utility loading Sanctorale from several sources and building a single Sanctorale by layering them over each other.
Class Method Summary collapse
-
.create_layered(*instances) ⇒ Sanctorale
Takes several Sanctorale instances, returns a new one, created by merging them all together (using CalendariumRomanum::Sanctorale#update).
-
.load_layered_from_files(*paths) ⇒ Sanctorale
Takes several filesystem paths, loads a Sanctorale from each of them (using SanctoraleLoader) and then merges them (using SanctoraleFactory.create_layered).
-
.load_with_parents(path) ⇒ Sanctorale
Takes a single filesystem path.
Class Method Details
.create_layered(*instances) ⇒ Sanctorale
Takes several CalendariumRomanum::Sanctorale instances, returns a new one, created by merging them all together (using CalendariumRomanum::Sanctorale#update)
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/calendarium-romanum/sanctorale_factory.rb', line 21 def create_layered(*instances) r = Sanctorale.new instances.each {|i| r.update i } = instances .collect(&:metadata) .select {|i| i.is_a? Hash } r. = .inject((.first || {}).dup) {|merged,i| merged.update i } r..delete 'extends' r.['components'] = instances.collect(&:metadata) r end |
.load_layered_from_files(*paths) ⇒ Sanctorale
Takes several filesystem paths, loads a CalendariumRomanum::Sanctorale from each of them (using CalendariumRomanum::SanctoraleLoader) and then merges them (using create_layered)
48 49 50 51 52 53 54 |
# File 'lib/calendarium-romanum/sanctorale_factory.rb', line 48 def load_layered_from_files(*paths) loader = SanctoraleLoader.new instances = paths.collect do |p| loader.load_from_file p end create_layered(*instances) end |
.load_with_parents(path) ⇒ Sanctorale
Takes a single filesystem path. If the file’s YAML front matter references any parent data files using the ‘extends’ key, it loads all the parents and assembles the resulting CalendariumRomanum::Sanctorale. If the data file doesn’t reference any parents, result is the same as CalendariumRomanum::SanctoraleLoader#load_from_file.
65 66 67 68 69 70 71 72 |
# File 'lib/calendarium-romanum/sanctorale_factory.rb', line 65 def load_with_parents(path) loader = SanctoraleLoader.new hierarchy = load_parent_hierarchy(path, loader) return hierarchy.first if hierarchy.size == 1 create_layered *hierarchy end |