Class: TZInfo::CountryInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/country_info.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name, &block) ⇒ CountryInfo

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).



35
36
37
38
39
40
41
# File 'lib/tzinfo/country_info.rb', line 35

def initialize(code, name, &block)
  @code = code
  @name = name
  @block = block
  @zones = nil
  @zone_identifiers = nil
end

Instance Attribute Details

#codeObject (readonly)

:nodoc:



29
30
31
# File 'lib/tzinfo/country_info.rb', line 29

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/tzinfo/country_info.rb', line 30

def name
  @name
end

Instance Method Details

#inspectObject

Returns internal object state as a programmer-readable string.



64
65
66
# File 'lib/tzinfo/country_info.rb', line 64

def inspect
  "#<#{self.class}: #@code>"
end

#timezone(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) ⇒ Object

Called by the index data to define a timezone for the country.



44
45
46
47
48
49
50
# File 'lib/tzinfo/country_info.rb', line 44

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

#zone_identifiersObject

Returns a frozen array of all the zone identifiers for the country. These are in the order they were added using the timezone method.



54
55
56
57
58
59
60
61
# File 'lib/tzinfo/country_info.rb', line 54

def zone_identifiers
  unless @zone_identifiers
    @zone_identifiers = zones.collect {|zone| zone.identifier}
    @zone_identifiers.freeze
  end
  
  @zone_identifiers
end

#zonesObject

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.



71
72
73
74
75
76
77
78
79
80
# File 'lib/tzinfo/country_info.rb', line 71

def zones
  unless @zones
    @zones = []
    @block.call(self) if @block
    @block = nil
    @zones.freeze
  end
  
  @zones
end