Class: Z4grid::Maidenhead
- Inherits:
-
Object
- Object
- Z4grid::Maidenhead
- Defined in:
- lib/z4grid.rb
Class Method Summary collapse
- .to_latlon(location) ⇒ Object
- .to_maidenhead(lat, lon, precision = 5) ⇒ Object
- .valid_maidenhead?(location) ⇒ Boolean
Instance Method Summary collapse
- #lat ⇒ Object
- #lat=(pos) ⇒ Object
- #locator ⇒ Object
- #locator=(location) ⇒ Object
- #lon ⇒ Object
- #lon=(pos) ⇒ Object
- #precision ⇒ Object
- #precision=(value) ⇒ Object
Class Method Details
.to_latlon(location) ⇒ Object
26 27 28 |
# File 'lib/z4grid.rb', line 26 def self.to_latlon(location); maidenhead = Maidenhead.new; maidenhead.locator = location; return [ maidenhead.lat, maidenhead.lon ] end |
.to_maidenhead(lat, lon, precision = 5) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/z4grid.rb', line 43 def self.to_maidenhead(lat, lon, precision = 5) maidenhead = Maidenhead.new maidenhead.lat = lat maidenhead.lon = lon maidenhead.precision = precision maidenhead.locator end |
.valid_maidenhead?(location) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/z4grid.rb', line 8 def self.valid_maidenhead?(location) return false unless location.is_a?String return false unless location.length >= 2 return false unless (location.length % 2) == 0 length = location.length / 2 length.times do |counter| grid = location[counter * 2, 2] if (counter == 0) return false unless grid =~ /[a-rA-R]{2}/ elsif (counter % 2) == 0 return false unless grid =~ /[a-xA-X]{2}/ else return false unless grid =~ /[0-9]{2}/ end end true end |
Instance Method Details
#lat ⇒ Object
51 |
# File 'lib/z4grid.rb', line 51 def lat; @lat.round(6); end |
#lat=(pos) ⇒ Object
50 |
# File 'lib/z4grid.rb', line 50 def lat=(pos); @lat = range_check("lat", 90.0, pos); end |
#locator ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/z4grid.rb', line 56 def locator @locator = '' @lat_tmp = @lat + 90.0 @lon_tmp = @lon + 180.0 @precision_tmp = @precision calculate_field calculate_values @locator end |
#locator=(location) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/z4grid.rb', line 29 def locator=(location) unless Maidenhead.valid_maidenhead?(location) raise ArgumentError.new("Location is not a valid Maidenhead Locator System string") end @locator = location @lat = -90.0 @lon = -180.0 pad_locator convert_part_to_latlon(0, 1) convert_part_to_latlon(1, 10) convert_part_to_latlon(2, 10 * 24) convert_part_to_latlon(3, 10 * 24 * 10) convert_part_to_latlon(4, 10 * 24 * 10 * 24) end |
#lon ⇒ Object
53 |
# File 'lib/z4grid.rb', line 53 def lon; @lon.round(6); end |
#lon=(pos) ⇒ Object
52 |
# File 'lib/z4grid.rb', line 52 def lon=(pos); @lon = range_check("lon", 180.0, pos); end |
#precision ⇒ Object
55 |
# File 'lib/z4grid.rb', line 55 def precision; @precision; end |
#precision=(value) ⇒ Object
54 |
# File 'lib/z4grid.rb', line 54 def precision=(value); @precision = value; end |