Sha256: 7e623404033ee908f9a26b67515e0c02c6b6362a442987727e5767c3994192b4

Contents?: true

Size: 710 Bytes

Versions: 3

Compression:

Stored size: 710 Bytes

Contents

require 'geocoder/results/base'

module Geocoder::Result
  class Freegeoip < Base

    def address(format = :full)
      "#{city}#{', ' + state_code unless state_code == ''} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
    end

    def city
      @data['city']
    end

    def state
      @data['region_name']
    end

    def state_code
      @data['region_code']
    end

    def country
      @data['country_name']
    end

    def country_code
      @data['country_code']
    end

    def postal_code
      @data['zipcode']
    end

    def self.response_attributes
      %w[metrocode ip]
    end

    response_attributes.each do |a|
      define_method a do
        @data[a]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geocoder-1.0.2 lib/geocoder/results/freegeoip.rb
geocoder-1.0.1 lib/geocoder/results/freegeoip.rb
geocoder-1.0.0 lib/geocoder/results/freegeoip.rb