Class: TZInfo::TZDataLocation

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

Overview

A location (latitude + longitude)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coordinates) ⇒ TZDataLocation

Constructs a new TZDataLocation from a string in ISO 6709 sign-degrees-minutes-seconds format, either -DDMM-DDDMM or -DDMMSS-DDDMMSS, first latitude (+ is north), then longitude (+ is east).



1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
# File 'lib/tzinfo/tzdataparser.rb', line 1121

def initialize(coordinates)
  if coordinates !~ /^([+\-])([0-9]{2})([0-9]{2})([0-9]{2})?([+\-])([0-9]{3})([0-9]{2})([0-9]{2})?$/
    raise "Invalid coordinates: #{coordinates}"
  end
  
  @latitude = Rational($2.to_i) + Rational($3.to_i, 60)
  @latitude += Rational($4.to_i, 3600) unless $4.nil?
  @latitude = -@latitude if $1 == '-'
  
  @longitude = Rational($6.to_i) + Rational($7.to_i, 60)
  @longitude += Rational($8.to_i, 3600) unless $8.nil?
  @longitude = -@longitude if $5 == '-'
end

Instance Attribute Details

#latitudeObject (readonly)

:nodoc:



1114
1115
1116
# File 'lib/tzinfo/tzdataparser.rb', line 1114

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



1115
1116
1117
# File 'lib/tzinfo/tzdataparser.rb', line 1115

def longitude
  @longitude
end