lib/tzinfo/country_info.rb in tzinfo-0.3.62 vs lib/tzinfo/country_info.rb in tzinfo-1.0.0

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2006-2013 Philip Ross +# Copyright (c) 2013 Philip Ross # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -19,64 +19,40 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. #++ module TZInfo - # Class to store the data loaded from the country index. Instances of this - # class are passed to the blocks in the index that define timezones. - # - # @private - class CountryInfo #:nodoc: + # Represents a country and references to its timezones as returned by a + # DataSource. + class CountryInfo + # The ISO 3166 country code. attr_reader :code + + # The name of the country. attr_reader :name - # Constructs a new CountryInfo with an ISO 3166 country code, name and - # block. The block will be evaluated to obtain the timezones for the country - # (when they are first needed). - def initialize(code, name, &block) + # Constructs a new CountryInfo with an ISO 3166 country code and name + def initialize(code, name) @code = code @name = name - @block = block - @zones = nil - @zone_identifiers = nil end - # Called by the index data to define a timezone for the country. - def timezone(identifier, latitude_numerator, latitude_denominator, - longitude_numerator, longitude_denominator, description = nil) - # Currently only store the identifiers. - @zones << CountryTimezone.new(identifier, latitude_numerator, - latitude_denominator, longitude_numerator, longitude_denominator, - description) - end - - # Returns a frozen array of all the zone identifiers for the country. These - # are in the order they were added using the timezone method. - def zone_identifiers - unless @zone_identifiers - @zone_identifiers = zones.collect {|zone| zone.identifier} - @zone_identifiers.freeze - end - - @zone_identifiers - end - # Returns internal object state as a programmer-readable string. def inspect "#<#{self.class}: #@code>" end + # Returns a frozen array of all the zone identifiers for the country. + # The identifiers are ordered by importance according to the DataSource. + def zone_identifiers + raise NotImplementedError, 'Subclasses must override zone_identifiers' + end + # Returns a frozen array of all the timezones for the for the country as - # CountryTimezone instances. These are in the order they were added using - # the timezone method. + # CountryTimezone instances. + # + # The timezones are ordered by importance according to the DataSource. def zones - unless @zones - @zones = [] - @block.call(self) if @block - @block = nil - @zones.freeze - end - - @zones - end + raise NotImplementedError, 'Subclasses must override zone_identifiers' + end end end