Class: TwitterCldr::Shared::Calendar
- Inherits:
-
Object
- Object
- TwitterCldr::Shared::Calendar
- Defined in:
- lib/twitter_cldr/shared/calendar.rb
Constant Summary collapse
- DEFAULT_FORMAT =
:'stand-alone'
- DEFAULT_PERIOD_FORMAT =
:format
- NAMES_FORMS =
[:wide, :narrow, :short, :abbreviated, :foo]
- 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
-
#calendar_type ⇒ Object
readonly
Returns the value of attribute calendar_type.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
Instance Method Summary collapse
- #calendar_data ⇒ Object
- #date_order(options = {}) ⇒ Object
- #datetime_order(options = {}) ⇒ Object
- #eras(names_form = :name) ⇒ Object
- #fields ⇒ Object
-
#initialize(locale = TwitterCldr.locale, calendar_type = TwitterCldr::DEFAULT_CALENDAR_TYPE) ⇒ Calendar
constructor
A new instance of Calendar.
- #months(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object
- #periods(names_form = :wide, format = DEFAULT_PERIOD_FORMAT) ⇒ Object
- #quarters(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object
- #time_order(options = {}) ⇒ Object
- #weekdays(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object
Constructor Details
#initialize(locale = TwitterCldr.locale, calendar_type = TwitterCldr::DEFAULT_CALENDAR_TYPE) ⇒ Calendar
Returns a new instance of Calendar.
35 36 37 38 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 35 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_type ⇒ Object (readonly)
Returns the value of attribute calendar_type.
33 34 35 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 33 def calendar_type @calendar_type end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
33 34 35 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 33 def locale @locale end |
Instance Method Details
#calendar_data ⇒ Object
89 90 91 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 89 def calendar_data @calendar_data ||= TwitterCldr::Utils.traverse_hash(resource, [locale, :calendars, calendar_type]) end |
#date_order(options = {}) ⇒ Object
77 78 79 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 77 def date_order( = {}) get_order_for(TwitterCldr::DataReaders::DateDataReader, ) end |
#datetime_order(options = {}) ⇒ Object
85 86 87 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 85 def datetime_order( = {}) get_order_for(TwitterCldr::DataReaders::DateTimeDataReader, ) end |
#eras(names_form = :name) ⇒ Object
71 72 73 74 75 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 71 def eras(names_form = :name) cache_field_data(:eras, names_form) do get_data(:eras)[names_form] end end |
#fields ⇒ Object
53 54 55 56 57 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 53 def fields cache_field_data(:fields) do get_data(:fields) end end |
#months(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 40 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_PERIOD_FORMAT) ⇒ Object
65 66 67 68 69 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 65 def periods(names_form = :wide, format = DEFAULT_PERIOD_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
59 60 61 62 63 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 59 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
81 82 83 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 81 def time_order( = {}) get_order_for(TwitterCldr::DataReaders::TimeDataReader, ) end |
#weekdays(names_form = :wide, format = DEFAULT_FORMAT) ⇒ Object
47 48 49 50 51 |
# File 'lib/twitter_cldr/shared/calendar.rb', line 47 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 |