geocoder 1.5.1 → 1.6.7
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +45 -0
- data/LICENSE +1 -1
- data/README.md +16 -39
- data/bin/console +13 -0
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/geocoder/cache.rb +4 -0
- data/lib/geocoder/configuration.rb +2 -1
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +2 -1
- data/lib/geocoder/lookup.rb +8 -3
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +14 -1
- data/lib/geocoder/lookups/base.rb +2 -0
- data/lib/geocoder/lookups/esri.rb +6 -0
- data/lib/geocoder/lookups/freegeoip.rb +4 -4
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +8 -14
- data/lib/geocoder/lookups/google_places_search.rb +28 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/here.rb +7 -16
- data/lib/geocoder/lookups/ip2location.rb +5 -13
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/smarty_streets.rb +6 -1
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/tencent.rb +9 -9
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +3 -4
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +27 -2
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +4 -0
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/results/yandex.rb +217 -59
- data/lib/geocoder/sql.rb +4 -4
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +3 -3
- metadata +22 -16
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/hash_recursive_merge.rb +0 -74
    
        data/lib/geocoder/sql.rb
    CHANGED
    
    | @@ -44,13 +44,13 @@ module Geocoder | |
| 44 44 | 
             
                end
         | 
| 45 45 |  | 
| 46 46 | 
             
                def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr)
         | 
| 47 | 
            -
                  spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} AND "
         | 
| 47 | 
            +
                  spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND "
         | 
| 48 48 | 
             
                  # handle box that spans 180 longitude
         | 
| 49 49 | 
             
                  if sw_lng.to_f > ne_lng.to_f
         | 
| 50 | 
            -
                    spans + "(#{lon_attr} BETWEEN #{sw_lng} AND 180 OR " +
         | 
| 51 | 
            -
                    "#{lon_attr} BETWEEN -180 AND #{ne_lng})"
         | 
| 50 | 
            +
                    spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " +
         | 
| 51 | 
            +
                    "#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})"
         | 
| 52 52 | 
             
                  else
         | 
| 53 | 
            -
                    spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}"
         | 
| 53 | 
            +
                    spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}"
         | 
| 54 54 | 
             
                  end
         | 
| 55 55 | 
             
                end
         | 
| 56 56 |  | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Geocoder
         | 
| 4 | 
            +
              module Util
         | 
| 5 | 
            +
                #
         | 
| 6 | 
            +
                # Recursive version of Hash#merge!
         | 
| 7 | 
            +
                #
         | 
| 8 | 
            +
                # Adds the contents of +h2+ to +h1+,
         | 
| 9 | 
            +
                # merging entries in +h1+ with duplicate keys with those from +h2+.
         | 
| 10 | 
            +
                #
         | 
| 11 | 
            +
                # Compared with Hash#merge!, this method supports nested hashes.
         | 
| 12 | 
            +
                # When both +h1+ and +h2+ contains an entry with the same key,
         | 
| 13 | 
            +
                # it merges and returns the values from both hashes.
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                #    h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
         | 
| 16 | 
            +
                #    h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 17 | 
            +
                #    recursive_hash_merge(h1, h2)   #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
         | 
| 18 | 
            +
                #
         | 
| 19 | 
            +
                # Simply using Hash#merge! would return
         | 
| 20 | 
            +
                #
         | 
| 21 | 
            +
                #    h1.merge!(h2)    #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 22 | 
            +
                #
         | 
| 23 | 
            +
                def self.recursive_hash_merge(h1, h2)
         | 
| 24 | 
            +
                  h1.merge!(h2) do |_key, oldval, newval|
         | 
| 25 | 
            +
                    oldval.class == h1.class ? self.recursive_hash_merge(oldval, newval) : newval
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
    
        data/lib/geocoder/version.rb
    CHANGED
    
    
    
        data/lib/maxmind_database.rb
    CHANGED
    
    | @@ -96,9 +96,9 @@ module Geocoder | |
| 96 96 |  | 
| 97 97 | 
             
                def archive_url_path(package)
         | 
| 98 98 | 
             
                  {
         | 
| 99 | 
            -
                    geolite_country_csv: " | 
| 100 | 
            -
                    geolite_city_csv: " | 
| 101 | 
            -
                    geolite_asn_csv: " | 
| 99 | 
            +
                    geolite_country_csv: "GeoLite2-Country-CSV.zip",
         | 
| 100 | 
            +
                    geolite_city_csv: "GeoLite2-City-CSV.zip",
         | 
| 101 | 
            +
                    geolite_asn_csv: "GeoLite2-ASN-CSV.zip"
         | 
| 102 102 | 
             
                  }[package]
         | 
| 103 103 | 
             
                end
         | 
| 104 104 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,19 +1,18 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: geocoder
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.6.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alex Reisner
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-04-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 | 
            -
            description:  | 
| 14 | 
            -
               | 
| 15 | 
            -
               | 
| 16 | 
            -
              frameworks too.
         | 
| 13 | 
            +
            description: Object geocoding (by street or IP address), reverse geocoding (coordinates
         | 
| 14 | 
            +
              to street address), distance queries for ActiveRecord and Mongoid, result caching,
         | 
| 15 | 
            +
              and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
         | 
| 17 16 | 
             
            email:
         | 
| 18 17 | 
             
            - alex@alexreisner.com
         | 
| 19 18 | 
             
            executables:
         | 
| @@ -24,11 +23,13 @@ files: | |
| 24 23 | 
             
            - CHANGELOG.md
         | 
| 25 24 | 
             
            - LICENSE
         | 
| 26 25 | 
             
            - README.md
         | 
| 26 | 
            +
            - bin/console
         | 
| 27 27 | 
             
            - bin/geocode
         | 
| 28 28 | 
             
            - examples/autoexpire_cache_dalli.rb
         | 
| 29 29 | 
             
            - examples/autoexpire_cache_redis.rb
         | 
| 30 30 | 
             
            - examples/cache_bypass.rb
         | 
| 31 31 | 
             
            - examples/reverse_geocode_job.rb
         | 
| 32 | 
            +
            - lib/easting_northing.rb
         | 
| 32 33 | 
             
            - lib/generators/geocoder/config/config_generator.rb
         | 
| 33 34 | 
             
            - lib/generators/geocoder/config/templates/initializer.rb
         | 
| 34 35 | 
             
            - lib/generators/geocoder/maxmind/geolite_city_generator.rb
         | 
| @@ -48,6 +49,7 @@ files: | |
| 48 49 | 
             
            - lib/geocoder/kernel_logger.rb
         | 
| 49 50 | 
             
            - lib/geocoder/logger.rb
         | 
| 50 51 | 
             
            - lib/geocoder/lookup.rb
         | 
| 52 | 
            +
            - lib/geocoder/lookups/abstract_api.rb
         | 
| 51 53 | 
             
            - lib/geocoder/lookups/amap.rb
         | 
| 52 54 | 
             
            - lib/geocoder/lookups/baidu.rb
         | 
| 53 55 | 
             
            - lib/geocoder/lookups/baidu_ip.rb
         | 
| @@ -59,7 +61,6 @@ files: | |
| 59 61 | 
             
            - lib/geocoder/lookups/esri.rb
         | 
| 60 62 | 
             
            - lib/geocoder/lookups/freegeoip.rb
         | 
| 61 63 | 
             
            - lib/geocoder/lookups/geocoder_ca.rb
         | 
| 62 | 
            -
            - lib/geocoder/lookups/geocoder_us.rb
         | 
| 63 64 | 
             
            - lib/geocoder/lookups/geocodio.rb
         | 
| 64 65 | 
             
            - lib/geocoder/lookups/geoip2.rb
         | 
| 65 66 | 
             
            - lib/geocoder/lookups/geoportail_lu.rb
         | 
| @@ -71,7 +72,9 @@ files: | |
| 71 72 | 
             
            - lib/geocoder/lookups/ip2location.rb
         | 
| 72 73 | 
             
            - lib/geocoder/lookups/ipapi_com.rb
         | 
| 73 74 | 
             
            - lib/geocoder/lookups/ipdata_co.rb
         | 
| 75 | 
            +
            - lib/geocoder/lookups/ipgeolocation.rb
         | 
| 74 76 | 
             
            - lib/geocoder/lookups/ipinfo_io.rb
         | 
| 77 | 
            +
            - lib/geocoder/lookups/ipregistry.rb
         | 
| 75 78 | 
             
            - lib/geocoder/lookups/ipstack.rb
         | 
| 76 79 | 
             
            - lib/geocoder/lookups/latlon.rb
         | 
| 77 80 | 
             
            - lib/geocoder/lookups/location_iq.rb
         | 
| @@ -80,8 +83,10 @@ files: | |
| 80 83 | 
             
            - lib/geocoder/lookups/maxmind.rb
         | 
| 81 84 | 
             
            - lib/geocoder/lookups/maxmind_geoip2.rb
         | 
| 82 85 | 
             
            - lib/geocoder/lookups/maxmind_local.rb
         | 
| 86 | 
            +
            - lib/geocoder/lookups/nationaal_georegister_nl.rb
         | 
| 83 87 | 
             
            - lib/geocoder/lookups/nominatim.rb
         | 
| 84 88 | 
             
            - lib/geocoder/lookups/opencagedata.rb
         | 
| 89 | 
            +
            - lib/geocoder/lookups/osmnames.rb
         | 
| 85 90 | 
             
            - lib/geocoder/lookups/pelias.rb
         | 
| 86 91 | 
             
            - lib/geocoder/lookups/pickpoint.rb
         | 
| 87 92 | 
             
            - lib/geocoder/lookups/pointpin.rb
         | 
| @@ -91,6 +96,7 @@ files: | |
| 91 96 | 
             
            - lib/geocoder/lookups/telize.rb
         | 
| 92 97 | 
             
            - lib/geocoder/lookups/tencent.rb
         | 
| 93 98 | 
             
            - lib/geocoder/lookups/test.rb
         | 
| 99 | 
            +
            - lib/geocoder/lookups/uk_ordnance_survey_names.rb
         | 
| 94 100 | 
             
            - lib/geocoder/lookups/yandex.rb
         | 
| 95 101 | 
             
            - lib/geocoder/models/active_record.rb
         | 
| 96 102 | 
             
            - lib/geocoder/models/base.rb
         | 
| @@ -100,6 +106,7 @@ files: | |
| 100 106 | 
             
            - lib/geocoder/query.rb
         | 
| 101 107 | 
             
            - lib/geocoder/railtie.rb
         | 
| 102 108 | 
             
            - lib/geocoder/request.rb
         | 
| 109 | 
            +
            - lib/geocoder/results/abstract_api.rb
         | 
| 103 110 | 
             
            - lib/geocoder/results/amap.rb
         | 
| 104 111 | 
             
            - lib/geocoder/results/baidu.rb
         | 
| 105 112 | 
             
            - lib/geocoder/results/baidu_ip.rb
         | 
| @@ -111,7 +118,6 @@ files: | |
| 111 118 | 
             
            - lib/geocoder/results/esri.rb
         | 
| 112 119 | 
             
            - lib/geocoder/results/freegeoip.rb
         | 
| 113 120 | 
             
            - lib/geocoder/results/geocoder_ca.rb
         | 
| 114 | 
            -
            - lib/geocoder/results/geocoder_us.rb
         | 
| 115 121 | 
             
            - lib/geocoder/results/geocodio.rb
         | 
| 116 122 | 
             
            - lib/geocoder/results/geoip2.rb
         | 
| 117 123 | 
             
            - lib/geocoder/results/geoportail_lu.rb
         | 
| @@ -123,7 +129,9 @@ files: | |
| 123 129 | 
             
            - lib/geocoder/results/ip2location.rb
         | 
| 124 130 | 
             
            - lib/geocoder/results/ipapi_com.rb
         | 
| 125 131 | 
             
            - lib/geocoder/results/ipdata_co.rb
         | 
| 132 | 
            +
            - lib/geocoder/results/ipgeolocation.rb
         | 
| 126 133 | 
             
            - lib/geocoder/results/ipinfo_io.rb
         | 
| 134 | 
            +
            - lib/geocoder/results/ipregistry.rb
         | 
| 127 135 | 
             
            - lib/geocoder/results/ipstack.rb
         | 
| 128 136 | 
             
            - lib/geocoder/results/latlon.rb
         | 
| 129 137 | 
             
            - lib/geocoder/results/location_iq.rb
         | 
| @@ -132,8 +140,10 @@ files: | |
| 132 140 | 
             
            - lib/geocoder/results/maxmind.rb
         | 
| 133 141 | 
             
            - lib/geocoder/results/maxmind_geoip2.rb
         | 
| 134 142 | 
             
            - lib/geocoder/results/maxmind_local.rb
         | 
| 143 | 
            +
            - lib/geocoder/results/nationaal_georegister_nl.rb
         | 
| 135 144 | 
             
            - lib/geocoder/results/nominatim.rb
         | 
| 136 145 | 
             
            - lib/geocoder/results/opencagedata.rb
         | 
| 146 | 
            +
            - lib/geocoder/results/osmnames.rb
         | 
| 137 147 | 
             
            - lib/geocoder/results/pelias.rb
         | 
| 138 148 | 
             
            - lib/geocoder/results/pickpoint.rb
         | 
| 139 149 | 
             
            - lib/geocoder/results/pointpin.rb
         | 
| @@ -143,6 +153,7 @@ files: | |
| 143 153 | 
             
            - lib/geocoder/results/telize.rb
         | 
| 144 154 | 
             
            - lib/geocoder/results/tencent.rb
         | 
| 145 155 | 
             
            - lib/geocoder/results/test.rb
         | 
| 156 | 
            +
            - lib/geocoder/results/uk_ordnance_survey_names.rb
         | 
| 146 157 | 
             
            - lib/geocoder/results/yandex.rb
         | 
| 147 158 | 
             
            - lib/geocoder/sql.rb
         | 
| 148 159 | 
             
            - lib/geocoder/stores/active_record.rb
         | 
| @@ -150,8 +161,8 @@ files: | |
| 150 161 | 
             
            - lib/geocoder/stores/mongo_base.rb
         | 
| 151 162 | 
             
            - lib/geocoder/stores/mongo_mapper.rb
         | 
| 152 163 | 
             
            - lib/geocoder/stores/mongoid.rb
         | 
| 164 | 
            +
            - lib/geocoder/util.rb
         | 
| 153 165 | 
             
            - lib/geocoder/version.rb
         | 
| 154 | 
            -
            - lib/hash_recursive_merge.rb
         | 
| 155 166 | 
             
            - lib/maxmind_database.rb
         | 
| 156 167 | 
             
            - lib/tasks/geocoder.rake
         | 
| 157 168 | 
             
            - lib/tasks/maxmind.rake
         | 
| @@ -161,11 +172,7 @@ licenses: | |
| 161 172 | 
             
            metadata:
         | 
| 162 173 | 
             
              source_code_uri: https://github.com/alexreisner/geocoder
         | 
| 163 174 | 
             
              changelog_uri: https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md
         | 
| 164 | 
            -
            post_install_message:  | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
              NOTE: Geocoder's default IP address lookup has changed from FreeGeoIP.net to IPInfo.io. If you explicitly specify :freegeoip in your configuration you must choose a different IP lookup before FreeGeoIP is discontinued on July 1, 2018. If you do not explicitly specify :freegeoip you do not need to change anything.
         | 
| 168 | 
            -
             | 
| 175 | 
            +
            post_install_message: 
         | 
| 169 176 | 
             
            rdoc_options: []
         | 
| 170 177 | 
             
            require_paths:
         | 
| 171 178 | 
             
            - lib
         | 
| @@ -180,8 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 180 187 | 
             
                - !ruby/object:Gem::Version
         | 
| 181 188 | 
             
                  version: '0'
         | 
| 182 189 | 
             
            requirements: []
         | 
| 183 | 
            -
             | 
| 184 | 
            -
            rubygems_version: 2.5.2
         | 
| 190 | 
            +
            rubygems_version: 3.1.2
         | 
| 185 191 | 
             
            signing_key: 
         | 
| 186 192 | 
             
            specification_version: 4
         | 
| 187 193 | 
             
            summary: Complete geocoding solution for Ruby.
         | 
| @@ -1,51 +0,0 @@ | |
| 1 | 
            -
            require 'geocoder/lookups/base'
         | 
| 2 | 
            -
            require "geocoder/results/geocoder_us"
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            module Geocoder::Lookup
         | 
| 5 | 
            -
              class GeocoderUs < Base
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                def name
         | 
| 8 | 
            -
                  "Geocoder.us"
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def supported_protocols
         | 
| 12 | 
            -
                  [:http]
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                private # ----------------------------------------------------------------
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                def base_query_url(query)
         | 
| 18 | 
            -
                  base_query_url_with_optional_key(configuration.api_key)
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                def cache_key(query)
         | 
| 22 | 
            -
                  base_query_url_with_optional_key(nil) + url_query_string(query)
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                def base_query_url_with_optional_key(key = nil)
         | 
| 26 | 
            -
                  base = "#{protocol}://"
         | 
| 27 | 
            -
                  if configuration.api_key
         | 
| 28 | 
            -
                    base << "#{configuration.api_key}@"
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
                  base + "geocoder.us/member/service/csv/geocode?"
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def results(query)
         | 
| 34 | 
            -
                  return [] unless doc = fetch_data(query)
         | 
| 35 | 
            -
                  if doc[0].to_s =~ /^(\d+)\:/
         | 
| 36 | 
            -
                    return []
         | 
| 37 | 
            -
                  else
         | 
| 38 | 
            -
                    return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc]
         | 
| 39 | 
            -
                  end
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                def query_url_params(query)
         | 
| 43 | 
            -
                  (query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super)
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                def parse_raw_data(raw_data)
         | 
| 47 | 
            -
                  raw_data.chomp.split(',')
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
            end
         | 
| 51 | 
            -
             | 
| @@ -1,39 +0,0 @@ | |
| 1 | 
            -
            require 'geocoder/results/base'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module Geocoder::Result
         | 
| 4 | 
            -
              class GeocoderUs < Base
         | 
| 5 | 
            -
                def coordinates
         | 
| 6 | 
            -
                  [@data[0].to_f, @data[1].to_f]
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                def address(format = :full)
         | 
| 10 | 
            -
                  "#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                def street_address
         | 
| 14 | 
            -
                  @data[2]
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                def city
         | 
| 18 | 
            -
                  @data[3]
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                def state
         | 
| 22 | 
            -
                  @data[4]
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                alias_method :state_code, :state
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def postal_code
         | 
| 28 | 
            -
                  @data[5]
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def country
         | 
| 32 | 
            -
                  'United States'
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                def country_code
         | 
| 36 | 
            -
                  'US'
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
            end
         | 
    
        data/lib/hash_recursive_merge.rb
    DELETED
    
    | @@ -1,74 +0,0 @@ | |
| 1 | 
            -
            # 
         | 
| 2 | 
            -
            # = Hash Recursive Merge
         | 
| 3 | 
            -
            # 
         | 
| 4 | 
            -
            # Merges a Ruby Hash recursively, Also known as deep merge.
         | 
| 5 | 
            -
            # Recursive version of Hash#merge and Hash#merge!.
         | 
| 6 | 
            -
            # 
         | 
| 7 | 
            -
            # Category::    Ruby
         | 
| 8 | 
            -
            # Package::     Hash
         | 
| 9 | 
            -
            # Author::      Simone Carletti <weppos@weppos.net>
         | 
| 10 | 
            -
            # Copyright::   2007-2008 The Authors
         | 
| 11 | 
            -
            # License::     MIT License
         | 
| 12 | 
            -
            # Link::        http://www.simonecarletti.com/
         | 
| 13 | 
            -
            # Source::      http://gist.github.com/gists/6391/
         | 
| 14 | 
            -
            #
         | 
| 15 | 
            -
            module HashRecursiveMerge
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              #
         | 
| 18 | 
            -
              # Recursive version of Hash#merge!
         | 
| 19 | 
            -
              # 
         | 
| 20 | 
            -
              # Adds the contents of +other_hash+ to +hsh+, 
         | 
| 21 | 
            -
              # merging entries in +hsh+ with duplicate keys with those from +other_hash+.
         | 
| 22 | 
            -
              # 
         | 
| 23 | 
            -
              # Compared with Hash#merge!, this method supports nested hashes.
         | 
| 24 | 
            -
              # When both +hsh+ and +other_hash+ contains an entry with the same key,
         | 
| 25 | 
            -
              # it merges and returns the values from both arrays.
         | 
| 26 | 
            -
              # 
         | 
| 27 | 
            -
              #    h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
         | 
| 28 | 
            -
              #    h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 29 | 
            -
              #    h1.rmerge!(h2)   #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
         | 
| 30 | 
            -
              #    
         | 
| 31 | 
            -
              # Simply using Hash#merge! would return
         | 
| 32 | 
            -
              # 
         | 
| 33 | 
            -
              #    h1.merge!(h2)    #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 34 | 
            -
              # 
         | 
| 35 | 
            -
              def rmerge!(other_hash)
         | 
| 36 | 
            -
                merge!(other_hash) do |key, oldval, newval|
         | 
| 37 | 
            -
                  oldval.class == self.class ? oldval.rmerge!(newval) : newval
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
              end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
              #
         | 
| 42 | 
            -
              # Recursive version of Hash#merge
         | 
| 43 | 
            -
              # 
         | 
| 44 | 
            -
              # Compared with Hash#merge!, this method supports nested hashes.
         | 
| 45 | 
            -
              # When both +hsh+ and +other_hash+ contains an entry with the same key,
         | 
| 46 | 
            -
              # it merges and returns the values from both arrays.
         | 
| 47 | 
            -
              # 
         | 
| 48 | 
            -
              # Compared with Hash#merge, this method provides a different approch
         | 
| 49 | 
            -
              # for merging nasted hashes.
         | 
| 50 | 
            -
              # If the value of a given key is an Hash and both +other_hash+ abd +hsh
         | 
| 51 | 
            -
              # includes the same key, the value is merged instead replaced with
         | 
| 52 | 
            -
              # +other_hash+ value.
         | 
| 53 | 
            -
              # 
         | 
| 54 | 
            -
              #    h1 = {"a" => 100, "b" => 200, "c" => {"c1" => 12, "c2" => 14}}
         | 
| 55 | 
            -
              #    h2 = {"b" => 254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 56 | 
            -
              #    h1.rmerge(h2)    #=> {"a" => 100, "b" => 254, "c" => {"c1" => 16, "c2" => 14, "c3" => 94}}
         | 
| 57 | 
            -
              #    
         | 
| 58 | 
            -
              # Simply using Hash#merge would return
         | 
| 59 | 
            -
              # 
         | 
| 60 | 
            -
              #    h1.merge(h2)     #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}}
         | 
| 61 | 
            -
              # 
         | 
| 62 | 
            -
              def rmerge(other_hash)
         | 
| 63 | 
            -
                r = {}
         | 
| 64 | 
            -
                merge(other_hash) do |key, oldval, newval|
         | 
| 65 | 
            -
                  r[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval
         | 
| 66 | 
            -
                end
         | 
| 67 | 
            -
              end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
            end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
            class Hash
         | 
| 73 | 
            -
              include HashRecursiveMerge
         | 
| 74 | 
            -
            end
         |