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



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

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

Instance Attribute Details

#codeObject (readonly)

:nodoc:



27
28
29
# File 'lib/tzinfo/country_info.rb', line 27

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#inspectObject

Returns internal object state as a programmer-readable string.



62
63
64
# File 'lib/tzinfo/country_info.rb', line 62

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.



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

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.



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

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.



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

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