Class: NationalHolidays::Country
- Inherits:
-
Object
- Object
- NationalHolidays::Country
- Defined in:
- lib/national_holidays/country.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code) ⇒ Country
constructor
A new instance of Country.
- #regions ⇒ Object
Constructor Details
#initialize(code) ⇒ Country
Returns a new instance of Country.
15 16 17 18 |
# File 'lib/national_holidays/country.rb', line 15 def initialize(code) @code = code.to_sym @name = ISO3166::Country.new(code).name end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/national_holidays/country.rb', line 7 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/national_holidays/country.rb', line 7 def name @name end |
Class Method Details
.all ⇒ Object
9 10 11 12 13 |
# File 'lib/national_holidays/country.rb', line 9 def self.all Dir.glob("#{NationalHolidays.config_directory}/*").sort.map do |country_directory| new(File.basename(country_directory)) end end |
Instance Method Details
#regions ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/national_holidays/country.rb', line 20 def regions dir = "#{NationalHolidays.config_directory}/#{code}" raise NationalHolidays::UnknownCountryError, "Unknown country: #{code}" unless Dir.exist?(dir) Dir.glob("#{dir}/*.yml").sort.map do |filename| Region.new(File.basename(filename).sub(/\.yml/, '')) end end |