Class: Calrom::Config
- Inherits:
-
Object
- Object
- Calrom::Config
- Defined in:
- lib/calrom/config.rb
Constant Summary collapse
- DEFAULT_DATA =
CR::Data::GENERAL_ROMAN_ENGLISH
- DEFAULT_LOCALE =
:en
- ATTRIBUTES =
[ :today, :date_range, :formatter, :colours, :sanctorale, :transfer_to_sunday, :temporale_extensions, :locale, :configs, :load_parents, :highlight, :verbose, :filter_days, :filter_celebrations, ]
Instance Method Summary collapse
- #==(b) ⇒ Object
- #build_formatter ⇒ Object
- #build_highlighter(colourful) ⇒ Object
- #build_sanctorale ⇒ Object
- #calendar ⇒ Object
- #highlight ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_parents? ⇒ Boolean
Should calendars be loaded including parent files they reference?.
- #locale ⇒ Object
- #temporale_options ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/calrom/config.rb', line 6 def initialize self.today = Date.today self.date_range = Month.new(today.year, today.month) self.sanctorale = [] self.configs = [] self.verbose = false self.highlight = Set.new(%i(colour rank today)) self.transfer_to_sunday = [] self.temporale_extensions = [] self.filter_days = [] self.filter_celebrations = [] end |
Instance Method Details
#==(b) ⇒ Object
38 39 40 41 |
# File 'lib/calrom/config.rb', line 38 def ==(b) self.class == b.class && ATTRIBUTES.all? {|prop| public_send(prop) == b.public_send(prop) } end |
#build_formatter ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/calrom/config.rb', line 103 def build_formatter highlighter = Highlighter::List klass = @formatter && Formatter.const_get(@formatter.capitalize) if @formatter.nil? klass = date_range.is_a?(Day) ? Formatter::List : Formatter::Overview end if [Formatter::Calendars, Formatter::Overview].include? klass highlighter = Highlighter::Overview end klass.new build_highlighter(highlighter), today end |
#build_highlighter(colourful) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/calrom/config.rb', line 118 def build_highlighter(colourful) if (self.colours == false || (self.colours.nil? && !STDOUT.isatty)) return Highlighter::No.new end Highlighter::Selective.new highlight, colourful.new end |
#build_sanctorale ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/calrom/config.rb', line 62 def build_sanctorale if @sanctorale.empty? return DEFAULT_DATA.load end data = @sanctorale.collect do |s| = File. s if s == '-' CR::SanctoraleLoader.new.load_from_string STDIN.read else data_file = if File.file? SanctoraleFile.new elsif CR::Data[s] CR::Data[s] else raise InputError.new "\"#{s}\" is neither a file, nor a valid identifier of a bundled calendar. " + "Valid identifiers are: " + CR::Data.each.collect(&:siglum).inspect end if load_parents? data_file.load_with_parents else data_file.load end end end CR::SanctoraleFactory.create_layered(*data) end |
#calendar ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/calrom/config.rb', line 43 def calendar calendar = if is_remote_calendar? if @sanctorale.size > 1 raise InputError.new '--calendar option provided multiple times, but at least one of the calendars is remote. Remote calendars cannot be layered.' end CR::Remote::Calendar.new date_range.first.year, @sanctorale.last else CR::PerpetualCalendar.new(sanctorale: build_sanctorale, temporale_options: , vespers: true) end FilteringCalendar.new( calendar, filter_days, filter_celebrations, ) end |
#highlight ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/calrom/config.rb', line 132 def highlight if date_range.is_a? Day @highlight - [:today] else @highlight end end |
#load_parents? ⇒ Boolean
Should calendars be loaded including parent files they reference?
127 128 129 130 |
# File 'lib/calrom/config.rb', line 127 def load_parents? load_parents == true || (load_parents.nil? && @sanctorale.size == 1) end |
#locale ⇒ Object
99 100 101 |
# File 'lib/calrom/config.rb', line 99 def locale @locale || || DEFAULT_LOCALE end |
#temporale_options ⇒ Object
95 96 97 |
# File 'lib/calrom/config.rb', line 95 def {transfer_to_sunday: transfer_to_sunday, extensions: temporale_extensions} end |