Class: TwitterCldr::Shared::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/shared/calendar.rb

Constant Summary collapse

DEFAULT_FORMAT =
:'stand-alone'
NAMES_FORMS =
[:wide, :narrow, :short, :abbreviated]
ERAS_NAMES_FORMS =
[:abbr, :name]
DATETIME_METHOD_MAP =
{
  year_of_week_of_year: :year,
  quarter_stand_alone: :quarter,
  month_stand_alone: :month,
  day_of_month: :day,
  day_of_week_in_month: :day,
  weekday_local: :weekday,
  weekday_local_stand_alone: :weekday,
  second_fraction: :second,
  timezone_generic_non_location: :timezone,
  timezone_metazone: :timezone
}
REDIRECT_CONVERSIONS =
{
  dayPeriods: :periods
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale = TwitterCldr.locale, calendar_type = TwitterCldr::DEFAULT_CALENDAR_TYPE) ⇒ Calendar

Returns a new instance of Calendar.



34
35
36
37
# File 'lib/twitter_cldr/shared/calendar.rb', line 34

def initialize(locale = TwitterCldr.locale, calendar_type = TwitterCldr::DEFAULT_CALENDAR_TYPE)
  @locale = TwitterCldr.convert_locale(locale)
  @calendar_type = calendar_type
end

Instance Attribute Details

#calendar_typeObject (readonly)

Returns the value of attribute calendar_type.



32
33
34
# File 'lib/twitter_cldr/shared/calendar.rb', line 32

def calendar_type
  @calendar_type
end

#localeObject (readonly)

Returns the value of attribute locale.



32
33
34
# File 'lib/twitter_cldr/shared/calendar.rb', line 32

def locale
  @locale
end

Instance Method Details

#calendar_dataObject



88
89
90
# File 'lib/twitter_cldr/shared/calendar.rb', line 88

def calendar_data
  @calendar_data ||= TwitterCldr::Utils.traverse_hash(resource, [locale, :calendars, calendar_type])
end

#date_order(options = {}) ⇒ Object



76
77
78
# File 'lib/twitter_cldr/shared/calendar.rb', line 76

def date_order(options = {})
  get_order_for(TwitterCldr::DataReaders::DateDataReader, options)
end

#datetime_order(options = {}) ⇒ Object



84
85
86
# File 'lib/twitter_cldr/shared/calendar.rb', line 84

def datetime_order(options = {})
  get_order_for(TwitterCldr::DataReaders::DateTimeDataReader, options)
end

#eras(names_form = :name) ⇒ Object



70
71
72
73
74
# File 'lib/twitter_cldr/shared/calendar.rb', line 70

def eras(names_form = :name)
  cache_field_data(:eras, names_form) do
    get_data(:eras)[names_form]
  end
end

#fieldsObject



52
53
54
55
56
# File 'lib/twitter_cldr/shared/calendar.rb', line 52

def fields
  cache_field_data(:fields) do
    get_data(:fields)
  end
end

#months(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object



39
40
41
42
43
44
# File 'lib/twitter_cldr/shared/calendar.rb', line 39

def months(names_form = :wide, format = DEFAULT_FORMAT)
  cache_field_data(:months, names_form, format) do
    data = get_with_names_form(:months, names_form, format)
    data && data.sort_by { |m| m.first }.map { |m| m.last }
  end
end

#periods(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object



64
65
66
67
68
# File 'lib/twitter_cldr/shared/calendar.rb', line 64

def periods(names_form = :wide, format = DEFAULT_FORMAT)
  cache_field_data(:periods, names_form, format) do
    get_with_names_form(:periods, names_form, format)
  end
end

#quarters(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object



58
59
60
61
62
# File 'lib/twitter_cldr/shared/calendar.rb', line 58

def quarters(names_form = :wide, format = DEFAULT_FORMAT)
  cache_field_data(:quarters, names_form, format) do
    get_with_names_form(:quarters, names_form, format)
  end
end

#time_order(options = {}) ⇒ Object



80
81
82
# File 'lib/twitter_cldr/shared/calendar.rb', line 80

def time_order(options = {})
  get_order_for(TwitterCldr::DataReaders::TimeDataReader, options)
end

#weekdays(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object



46
47
48
49
50
# File 'lib/twitter_cldr/shared/calendar.rb', line 46

def weekdays(names_form = :wide, format = DEFAULT_FORMAT)
  cache_field_data(:weekdays, names_form, format) do
    get_with_names_form(:days, names_form, format)
  end
end