Class: Calrom::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/calrom/config.rb

Constant Summary collapse

DEFAULT_DATA =
CR::Data::GENERAL_ROMAN_ENGLISH
DEFAULT_LOCALE =
:en

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
# 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 = []
end

Instance Attribute Details

#coloursObject

Returns the value of attribute colours.



13
14
15
# File 'lib/calrom/config.rb', line 13

def colours
  @colours
end

#configsObject

Returns the value of attribute configs.



13
14
15
# File 'lib/calrom/config.rb', line 13

def configs
  @configs
end

#date_rangeObject

Returns the value of attribute date_range.



13
14
15
# File 'lib/calrom/config.rb', line 13

def date_range
  @date_range
end

#formatterObject

Returns the value of attribute formatter.



13
14
15
# File 'lib/calrom/config.rb', line 13

def formatter
  @formatter
end

#localeObject

Returns the value of attribute locale.



13
14
15
# File 'lib/calrom/config.rb', line 13

def locale
  @locale
end

#sanctoraleObject

Returns the value of attribute sanctorale.



13
14
15
# File 'lib/calrom/config.rb', line 13

def sanctorale
  @sanctorale
end

#todayObject

Returns the value of attribute today.



13
14
15
# File 'lib/calrom/config.rb', line 13

def today
  @today
end

Instance Method Details

#build_sanctoraleObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/calrom/config.rb', line 19

def build_sanctorale
  if @sanctorale.empty?
    return DEFAULT_DATA.load
  end

  data = @sanctorale.collect do |s|
    if s == '-'
      CR::SanctoraleLoader.new.load_from_string STDIN.read
    elsif File.file? s
      CR::SanctoraleLoader.new.load_from_file s
    elsif CR::Data[s]
      CR::Data[s].load
    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
  end

  CR::SanctoraleFactory.create_layered(*data)
end

#calendarObject



15
16
17
# File 'lib/calrom/config.rb', line 15

def calendar
  CR::PerpetualCalendar.new(sanctorale: build_sanctorale)
end

#highlighter(colourful) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/calrom/config.rb', line 61

def highlighter(colourful)
  if (self.colours == false || (self.colours.nil? && !STDOUT.isatty))
    return Highlighter::No.new
  end

  colourful.new
end