Class: CalendariumRomanum::SanctoraleWriter
- Inherits:
-
Object
- Object
- CalendariumRomanum::SanctoraleWriter
- Defined in:
- lib/calendarium-romanum/sanctorale_writer.rb
Overview
Understands a custom plaintext calendar format and knows how to transform the Celebrations in a Sanctorale to this format.
For specification of the data format see README of the data directory, For a complete example see e.g. the file describing General Roman Calendar.
Constant Summary collapse
- RANK_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ Ranks::TRIDUUM => 's1.1', Ranks::PRIMARY => 's1.2', Ranks::SOLEMNITY_GENERAL => 's', Ranks::SOLEMNITY_PROPER => 's1.4', Ranks::FEAST_LORD_GENERAL => 'f2.5', Ranks::SUNDAY_UNPRIVILEGED => 'f2.6', Ranks::FEAST_GENERAL => 'f', Ranks::FEAST_PROPER => 'f2.8', Ranks::FERIAL_PRIVILEGED => 'f2.9', Ranks::MEMORIAL_GENERAL => 'm', Ranks::MEMORIAL_PROPER => 'm3.11', Ranks::MEMORIAL_OPTIONAL => 'm3.12', Ranks::FERIAL => 'm3.13', Ranks::COMMEMORATION => '4.0' }.freeze
- COLOUR_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ Colours::WHITE => 'W', Colours::VIOLET => 'V', Colours::GREEN => 'G', Colours::RED => 'R' }.freeze
Instance Method Summary collapse
-
#write(src, dest = nil) ⇒ String
(also: #write_to_string)
Write to an object which understands #<<.
-
#write_to_file(sanctorale, filename, encoding = 'utf-8') ⇒ void
Write to a filesystem path.
Instance Method Details
#write(src, dest = nil) ⇒ String Also known as: write_to_string
Write to an object which understands #<<
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/calendarium-romanum/sanctorale_writer.rb', line 53 def write(src, dest = nil) dest ||= String.new # Write metadata to YAML if present unless src..nil? || src..empty? dest << src..to_yaml dest << "---\n" end # Write each celebration, grouped by month with headings current_month = 0 src.each_day.sort_by{ |date, _| date }.each do |date, celebrations| if date.month > current_month current_month = date.month dest << "\n= #{current_month}\n" end celebrations.each do |c| dest << celebration_line(date, c) dest << "\n" end end dest end |
#write_to_file(sanctorale, filename, encoding = 'utf-8') ⇒ void
This method returns an undefined value.
Write to a filesystem path
87 88 89 90 91 |
# File 'lib/calendarium-romanum/sanctorale_writer.rb', line 87 def write_to_file(sanctorale, filename, encoding = 'utf-8') File.open(filename, 'w', encoding: encoding) do |f| write(sanctorale, f) end end |