Class: Maiden::Maidenhead
- Inherits:
-
Object
- Object
- Maiden::Maidenhead
- Defined in:
- lib/maiden.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
35 36 37 |
# File 'lib/maiden.rb', line 35 def self.to_latlon(location); maidenhead = Maidenhead.new; maidenhead.locator = location; return [ maidenhead.lat, maidenhead.lon ] end |
.to_maidenhead(lat, lon, precision = 5) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/maiden.rb', line 52 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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/maiden.rb', line 17 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
60 |
# File 'lib/maiden.rb', line 60 def lat; @lat.round(6); end |
#lat=(pos) ⇒ Object
59 |
# File 'lib/maiden.rb', line 59 def lat=(pos); @lat = range_check("lat", 90.0, pos); end |
#locator ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/maiden.rb', line 65 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/maiden.rb', line 38 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
62 |
# File 'lib/maiden.rb', line 62 def lon; @lon.round(6); end |
#lon=(pos) ⇒ Object
61 |
# File 'lib/maiden.rb', line 61 def lon=(pos); @lon = range_check("lon", 180.0, pos); end |
#precision ⇒ Object
64 |
# File 'lib/maiden.rb', line 64 def precision; @precision; end |
#precision=(value) ⇒ Object
63 |
# File 'lib/maiden.rb', line 63 def precision=(value); @precision = value; end |