Class: TZInfo::CountryTimezone
- Inherits:
-
Object
- Object
- TZInfo::CountryTimezone
- Defined in:
- lib/tzinfo/country_timezone.rb
Overview
A Timezone within a Country. This contains extra information about the Timezone that is specific to the Country (a Timezone could be used by multiple countries).
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
A description of this timezone in relation to the country, e.g.
-
#identifier ⇒ Object
readonly
The zone identifier.
Instance Method Summary collapse
-
#==(ct) ⇒ Object
Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).
-
#description_or_friendly_identifier ⇒ Object
if description is not nil, this method returns description; otherwise it returns timezone.friendly_identifier(true).
-
#eql?(ct) ⇒ Boolean
Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).
-
#hash ⇒ Object
Returns a hash of this CountryTimezone.
-
#initialize(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) ⇒ CountryTimezone
constructor
Creates a new CountryTimezone with a timezone identifier, latitude, longitude and description.
-
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
-
#latitude ⇒ Object
The latitude of this timezone in degrees as a Rational.
-
#longitude ⇒ Object
The longitude of this timezone in degrees as a Rational.
-
#timezone ⇒ Object
The Timezone (actually a TimezoneProxy for performance reasons).
Constructor Details
#initialize(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) ⇒ CountryTimezone
Creates a new CountryTimezone with a timezone identifier, latitude, longitude and description. The latitude and longitude are specified as rationals - a numerator and denominator. For performance reasons, the numerators and denominators must be specified in their lowest form.
CountryTimezone instances should not normally be constructed manually.
45 46 47 48 49 50 51 52 53 |
# File 'lib/tzinfo/country_timezone.rb', line 45 def initialize(identifier, latitude_numerator, latitude_denominator, longitude_numerator, longitude_denominator, description = nil) #:nodoc: @identifier = identifier @latitude_numerator = latitude_numerator @latitude_denominator = latitude_denominator @longitude_numerator = longitude_numerator @longitude_denominator = longitude_denominator @description = description end |
Instance Attribute Details
#description ⇒ Object (readonly)
A description of this timezone in relation to the country, e.g. “Eastern Time”. This is usually nil for countries having only a single Timezone.
37 38 39 |
# File 'lib/tzinfo/country_timezone.rb', line 37 def description @description end |
#identifier ⇒ Object (readonly)
The zone identifier.
32 33 34 |
# File 'lib/tzinfo/country_timezone.rb', line 32 def identifier @identifier end |
Instance Method Details
#==(ct) ⇒ Object
Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).
79 80 81 82 83 84 |
# File 'lib/tzinfo/country_timezone.rb', line 79 def ==(ct) ct.respond_to?(:identifier) && ct.respond_to?(:latitude) && ct.respond_to?(:longitude) && ct.respond_to?(:description) && identifier == ct.identifier && latitude == ct.latitude && longitude == ct.longitude && description == ct.description end |
#description_or_friendly_identifier ⇒ Object
if description is not nil, this method returns description; otherwise it returns timezone.friendly_identifier(true).
62 63 64 |
# File 'lib/tzinfo/country_timezone.rb', line 62 def description_or_friendly_identifier description || timezone.friendly_identifier(true) end |
#eql?(ct) ⇒ Boolean
Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).
89 90 91 |
# File 'lib/tzinfo/country_timezone.rb', line 89 def eql?(ct) self == ct end |
#hash ⇒ Object
Returns a hash of this CountryTimezone.
94 95 96 97 |
# File 'lib/tzinfo/country_timezone.rb', line 94 def hash @identifier.hash ^ @latitude_numerator.hash ^ @latitude_denominator.hash ^ @longitude_numerator.hash ^ @longitude_denominator.hash ^ @description.hash end |
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
100 101 102 |
# File 'lib/tzinfo/country_timezone.rb', line 100 def inspect "#<#{self.class}: #@identifier>" end |
#latitude ⇒ Object
The latitude of this timezone in degrees as a Rational.
67 68 69 |
# File 'lib/tzinfo/country_timezone.rb', line 67 def latitude @latitude ||= RubyCoreSupport.rational_new!(@latitude_numerator, @latitude_denominator) end |
#longitude ⇒ Object
The longitude of this timezone in degrees as a Rational.
72 73 74 |
# File 'lib/tzinfo/country_timezone.rb', line 72 def longitude @longitude ||= RubyCoreSupport.rational_new!(@longitude_numerator, @longitude_denominator) end |