Class: DateHolidays::Reader::Locale
- Inherits:
-
Object
- Object
- DateHolidays::Reader::Locale
- Defined in:
- lib/date_holidays/reader/locale.rb
Overview
Represents specific locale which contains holidays. This is the main entry point into the gem.
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#js_bridge ⇒ Object
readonly
Returns the value of attribute js_bridge.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#holidays(year, language: :en, types: Set.new) ⇒ Object
Returns DateHolidays::Reader::Holiday instances.
-
#initialize(country:, state: nil, region: nil, js_bridge: JsBridge.new) ⇒ Locale
constructor
A new instance of Locale.
- #languages ⇒ Object
-
#raw_holidays(year, language: :en, types: Set.new) ⇒ Object
Returns the holiday data as a hash exactly as returned from the date-holiday node module.
- #regions(language = :en) ⇒ Object
- #states(language = :en) ⇒ Object
- #time_zones ⇒ Object
Constructor Details
#initialize(country:, state: nil, region: nil, js_bridge: JsBridge.new) ⇒ Locale
Returns a new instance of Locale.
17 18 19 20 21 22 23 24 |
# File 'lib/date_holidays/reader/locale.rb', line 17 def initialize(country:, state: nil, region: nil, js_bridge: JsBridge.new) @country = country || raise(ArgumentError, 'a country is required') @state = state @region = region @js_bridge = js_bridge freeze end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
15 16 17 |
# File 'lib/date_holidays/reader/locale.rb', line 15 def country @country end |
#js_bridge ⇒ Object (readonly)
Returns the value of attribute js_bridge.
15 16 17 |
# File 'lib/date_holidays/reader/locale.rb', line 15 def js_bridge @js_bridge end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
15 16 17 |
# File 'lib/date_holidays/reader/locale.rb', line 15 def region @region end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
15 16 17 |
# File 'lib/date_holidays/reader/locale.rb', line 15 def state @state end |
Instance Method Details
#holidays(year, language: :en, types: Set.new) ⇒ Object
Returns DateHolidays::Reader::Holiday instances.
36 37 38 39 40 |
# File 'lib/date_holidays/reader/locale.rb', line 36 def holidays(year, language: :en, types: Set.new) raw_holidays(year, language: language, types: types).map do |raw_holiday| Holiday.make(transform_raw_holiday(raw_holiday)) end end |
#languages ⇒ Object
52 53 54 |
# File 'lib/date_holidays/reader/locale.rb', line 52 def languages js_bridge.extract(:languages, locale_selector) end |
#raw_holidays(year, language: :en, types: Set.new) ⇒ Object
Returns the holiday data as a hash exactly as returned from the date-holiday node module.
28 29 30 31 32 33 |
# File 'lib/date_holidays/reader/locale.rb', line 28 def raw_holidays(year, language: :en, types: Set.new) types = validate_and_convert_types_to_set(types) result = js_bridge.extract(:holidays, locale_selector, year, *lang_opts(language)) type_filter(result, types) end |
#regions(language = :en) ⇒ Object
46 47 48 49 50 |
# File 'lib/date_holidays/reader/locale.rb', line 46 def regions(language = :en) raise Caution::IllegalStateError, 'a state is required' unless state js_bridge.extract(:regions, locale_selector, *lang_opts(language)) end |
#states(language = :en) ⇒ Object
42 43 44 |
# File 'lib/date_holidays/reader/locale.rb', line 42 def states(language = :en) js_bridge.extract(:states, locale_selector, *lang_opts(language)) end |
#time_zones ⇒ Object
56 57 58 |
# File 'lib/date_holidays/reader/locale.rb', line 56 def time_zones js_bridge.extract(:time_zones, locale_selector) end |