Class: Calrom::Formatter::Calendars

Inherits:
Calrom::Formatter show all
Defined in:
lib/calrom/formatter/calendars.rb

Overview

Prints list of available bundled calendars

Instance Method Summary collapse

Instance Method Details

#call(calendar, date_range) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/calrom/formatter/calendars.rb', line 5

def call(calendar, date_range)
  last_locale = nil
  CR::Data.each do |d|
    sanctorale = d.load_with_parents
    meta = sanctorale.
    puts if last_locale && last_locale != meta['locale']
    default = d == Config::DEFAULT_DATA ? ' [default]' : ''
    puts "%-20s:  %s  [%s]%s" % [d.siglum, meta['title'], meta['locale'], default]

    next unless meta['components']

    parents =
      meta['components']
        .collect {|c| c['extends'] }
        .compact
        .map {|e| e.is_a?(Array) ? e : [e] } # 'extends' is String or Array
        .flatten
        .map {|p| p.sub(/\.\w{3,4}$/, '') } # file name to "siglum"
    parents.each {|p| puts "  <  #{p}" }
    last_locale = meta['locale']
  end
end