Sha256: aec7ec9c1580a0481dd8da13a9eb416522e361294c57d48cbe4dcfb51f59c967

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Ipgeolocation < Base

    def coordinates
      [@data['latitude'].to_f, @data['longitude'].to_f]
    end

    def address(format = :full)
      "#{city}, #{state} #{postal_code}, #{country_name}".sub(/^[ ,]*/, "")
    end

    def state
      @data['state_prov']
    end

    def state_code
      @data['state_prov']
    end

    def country
      @data['country_name']
    end

    def country_code
      @data['country_code2']
    end

    def postal_code
      @data['zipcode']
    end

    def self.response_attributes
      [
          ['ip', ''],
          ['hostname', ''],
          ['continent_code', ''],
          ['continent_name', ''],
          ['country_code2', ''],
          ['country_code3', ''],
          ['country_name', ''],
          ['country_capital',''],
          ['district',''],
          ['state_prov',''],
          ['city', ''],
          ['zipcode', ''],
          ['time_zone', {}],
          ['currency', {}]
      ]
    end

    response_attributes.each do |attr, default|
      define_method attr do
        @data[attr] || default
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/results/ipgeolocation.rb
geocoder-1.8.2 lib/geocoder/results/ipgeolocation.rb
geocoder-1.8.1 lib/geocoder/results/ipgeolocation.rb
geocoder-1.8.0 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.5 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.4 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.3 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.2 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.1 lib/geocoder/results/ipgeolocation.rb
geocoder-1.7.0 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.7 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.6 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.5 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.4 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.3 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.2 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.1 lib/geocoder/results/ipgeolocation.rb
geocoder-1.6.0 lib/geocoder/results/ipgeolocation.rb