Class: TwitterCldr::DataReaders::CalendarDataReader

Inherits:
DataReader
  • Object
show all
Defined in:
lib/twitter_cldr/data_readers/calendar_data_reader.rb

Constant Summary collapse

DEFAULT_TYPE =
:medium
TYPE_PATHS =
{
  full:       [:full, :pattern],
  long:       [:long, :pattern],
  medium:     [:medium, :pattern],
  short:      [:short, :pattern],
  additional: [:additional_formats]
}

Instance Attribute Summary collapse

Attributes inherited from DataReader

#locale

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DataReader

#pattern_at_path

Constructor Details

#initialize(locale, options = {}) ⇒ CalendarDataReader

Returns a new instance of CalendarDataReader.



28
29
30
31
32
33
34
# 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

Instance Attribute Details

#additional_formatObject (readonly)

Returns the value of attribute additional_format.



26
27
28
# File 'lib/twitter_cldr/data_readers/calendar_data_reader.rb', line 26

def additional_format
  @additional_format
end

#calendar_typeObject (readonly)

Returns the value of attribute calendar_type.



26
27
28
# File 'lib/twitter_cldr/data_readers/calendar_data_reader.rb', line 26

def calendar_type
  @calendar_type
end

#typeObject (readonly)

Returns the value of attribute type.



26
27
28
# File 'lib/twitter_cldr/data_readers/calendar_data_reader.rb', line 26

def type
  @type
end

Class Method Details

.typesObject



21
22
23
# File 'lib/twitter_cldr/data_readers/calendar_data_reader.rb', line 21

def types
  TYPE_PATHS.keys
end

Instance Method Details

#additional_format_selectorObject



48
49
50
51
52
# 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

#calendarObject



44
45
46
# File 'lib/twitter_cldr/data_readers/calendar_data_reader.rb', line 44

def calendar
  @calendar ||= TwitterCldr::Shared::Calendar.new(locale)
end

#patternObject



36
37
38
39
40
41
42
# 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