Class: CalendariumRomanum::SanctoraleFactory

Inherits:
Object
  • Object
show all
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

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)

Examples:

include CalendariumRomanum

prague_sanctorale = SanctoraleFactory.create_layered(
  Data['czech-cs'].load, # Czech Republic
  Data['czech-cechy-cs'].load, # Province of Bohemia
  Data['czech-praha-cs'].load, # Archdiocese of Prague
)

Returns:



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)

Examples:

include CalendariumRomanum

my_sanctorale = SanctoraleFactory.load_layered_from_files(
  'data/czech-cs.txt',
  'data/czech-cechy-cs.txt'
)

Returns:



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.

Returns:

Since:

  • 0.7.0



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