class TwitterCldr::DataReaders::CalendarDataReader

Constants

DEFAULT_TYPE
TYPE_PATHS

Attributes

additional_format[R]
calendar_type[R]
type[R]

Public Class Methods

new(locale, options = {}) click to toggle source
Calls superclass method
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 28
def initialize(locale, options = {})
  super(locale)
  @calendar_type = options[:calendar_type] || TwitterCldr::DEFAULT_CALENDAR_TYPE
  @type = options[:type] || type || :default
  @type = DEFAULT_TYPE if type == :default
  @additional_format = options[:additional_format]
end
types() click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 21
def types
  TYPE_PATHS.keys
end

Public Instance Methods

additional_format_selector() click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 48
def additional_format_selector
  @format_selector ||= AdditionalDateFormatSelector.new(
    traverse([:calendars, calendar_type, :additional_formats])
  )
end
calendar() click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 44
def calendar
  @calendar ||= TwitterCldr::Shared::Calendar.new(locale)
end
pattern() click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 36
def pattern
  if type == :additional
    additional_format_selector.find_closest(additional_format)
  else
    traverse(path_for(type, calendar_type) + TYPE_PATHS[type])
  end
end

Protected Instance Methods

mirror_resource(options) click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 74
def mirror_resource(options)
  from = options[:from]
  to = options[:to]

  from.each_pair do |key, value|
    if !to[key]
      to[key] = from[key]
    else
      if to[key].is_a?(Hash) and from[key].is_a?(Hash)
        mirror_resource(from: from[key], to: to[key])
      end
    end
  end
end
path_for(type, calendar_type) click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 56
def path_for(type, calendar_type)
  raise NotImplementedError
end
resource() click to toggle source
# File lib/twitter_cldr/data_readers/calendar_data_reader.rb, line 60
def resource
  @resource ||= begin
    resource = TwitterCldr.get_locale_resource(locale, :calendars)[locale]
    resource[:calendars].each_pair do |calendar_type, options|
      next if calendar_type == TwitterCldr::DEFAULT_CALENDAR_TYPE
      mirror_resource(
        from: resource[:calendars][TwitterCldr::DEFAULT_CALENDAR_TYPE],
        to:   resource[:calendars][calendar_type]
      )
    end
    resource
  end
end