geonames_client 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        data/Gemfile
    CHANGED
    
    
    
        data/lib/geonames_client.rb
    CHANGED
    
    | @@ -1,3 +1,4 @@ | |
| 1 | 
            +
            require "geonames_client/numeric_extensions"
         | 
| 1 2 | 
             
            require "geonames_client/version"
         | 
| 2 3 |  | 
| 3 4 | 
             
            module GeonamesClient
         | 
| @@ -6,9 +7,3 @@ module GeonamesClient | |
| 6 7 | 
             
              autoload :Service,           'geonames_client/service'
         | 
| 7 8 | 
             
              autoload :ServiceDefinition, 'geonames_client/service_definition'
         | 
| 8 9 | 
             
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            class Numeric
         | 
| 11 | 
            -
              def degrees
         | 
| 12 | 
            -
                self * Math::PI / 180
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: geonames_client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 19
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.0. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 1.0.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - C. Jason Harrelson
         | 
| @@ -101,9 +101,9 @@ files: | |
| 101 101 | 
             
            - Rakefile
         | 
| 102 102 | 
             
            - geonames_client.gemspec
         | 
| 103 103 | 
             
            - lib/geonames_client.rb
         | 
| 104 | 
            -
            - lib/geonames_client/_location.rb
         | 
| 105 104 | 
             
            - lib/geonames_client/location.rb
         | 
| 106 105 | 
             
            - lib/geonames_client/nearby_street.rb
         | 
| 106 | 
            +
            - lib/geonames_client/numeric_extensions.rb
         | 
| 107 107 | 
             
            - lib/geonames_client/service.rb
         | 
| 108 108 | 
             
            - lib/geonames_client/service_definition.rb
         | 
| 109 109 | 
             
            - lib/geonames_client/version.rb
         | 
| @@ -1,68 +0,0 @@ | |
| 1 | 
            -
            class Location
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              def self.deg2rad(deg)
         | 
| 4 | 
            -
                 (deg * Math::PI / 180)
         | 
| 5 | 
            -
              end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              def self.rad2deg(rad)
         | 
| 8 | 
            -
                 (rad * 180 / Math::PI)
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              def self.acos(rad)
         | 
| 12 | 
            -
                 Math.atan2(Math.sqrt(1 - rad**2), rad)
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              def self.distance_in_miles(loc1, loc2)
         | 
| 16 | 
            -
                 lat1 = loc1.latitude
         | 
| 17 | 
            -
                 lon1 = loc1.longitude
         | 
| 18 | 
            -
                 lat2 = loc2.latitude
         | 
| 19 | 
            -
                 lon2 = loc2.longitude
         | 
| 20 | 
            -
                 theta = lon1 - lon2
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                 dist = Math.sin(self.deg2rad(lat1)) * Math.sin(deg2rad(lat2))
         | 
| 23 | 
            -
                    + Math.cos(self.deg2rad(lat1)) * Math.cos(self.deg2rad(lat2)) * Math.cos(deg2rad(theta))
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                 dist = self.rad2deg(self.acos(dist))
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                 (dist * 60 * 1.1515).round #distance in miles
         | 
| 28 | 
            -
              end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              def miles_to(location)
         | 
| 31 | 
            -
                 Location.distance_in_miles(self, location)
         | 
| 32 | 
            -
              end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
              def self.locationArea(location, miles)
         | 
| 35 | 
            -
                 radius = miles.to_f
         | 
| 36 | 
            -
                 latR = radius / ((6076 / 5280) * 60)
         | 
| 37 | 
            -
                 lonR = radius / (((Math.cos(location.latitude * Math::PI / 180) * 6076) / 5280) * 60)
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                 {
         | 
| 40 | 
            -
                    :min_latitude => location.latitude - latR,
         | 
| 41 | 
            -
                    :min_longitude => location.longitude - lonR,
         | 
| 42 | 
            -
                    :max_latitude => location.latitude + latR,
         | 
| 43 | 
            -
                    :max_longitude => location.longitude + lonR
         | 
| 44 | 
            -
                 }
         | 
| 45 | 
            -
              end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
              def self.location_ids_in_range(location, miles)
         | 
| 48 | 
            -
                 la = Location.locationArea(location, miles)
         | 
| 49 | 
            -
                 Location.find(:all,
         | 
| 50 | 
            -
                    :select => Location.connection.quote_column_name( 'id' ),
         | 
| 51 | 
            -
                    :conditions => ["(#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'latitude'} <= ?) AND (#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'latitude'} >= ?) AND " +
         | 
| 52 | 
            -
                       "(#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'longitude'} >= ?) AND (#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'longitude'} <= ?)",
         | 
| 53 | 
            -
                       la[:max_latitude], la[:min_latitude], la[:min_longitude], la[:max_longitude]
         | 
| 54 | 
            -
                    ]
         | 
| 55 | 
            -
                 ).collect { |l| l.id }
         | 
| 56 | 
            -
              end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
              def self.locations_in_range(location, miles)
         | 
| 59 | 
            -
                 la = Location.locationArea(location, miles)
         | 
| 60 | 
            -
                 Location.find(:all,
         | 
| 61 | 
            -
                    :conditions => ["(#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'latitude'} <= ?) AND (#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'latitude'} >= ?) AND " +
         | 
| 62 | 
            -
                       "(#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'longitude'} >= ?) AND (#{connection.quote_table_name 'locations'}.#{connection.quote_column_name 'longitude'} <= ?)",
         | 
| 63 | 
            -
                       la[:max_latitude], la[:min_latitude], la[:min_longitude], la[:max_longitude]
         | 
| 64 | 
            -
                    ]
         | 
| 65 | 
            -
                 )
         | 
| 66 | 
            -
              end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
            end
         |