Sha256: 5a75b370ba13c234b27431223473e93daf94c44924f71f07503920199ff941a8

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

require 'happymapper'
require 'iconv' unless String.instance_methods.include?(:encode)

module Ipgeobase
  class IpMetaData
    include HappyMapper

    tag 'ip-answer'
    element :inetnum, String, :deep => true
    element :city, String, :deep => true
    element :country, String, :deep => true
    element :region, String, :deep => true
    element :district, String, :deep => true
    element :lat, Float, :deep => true
    element :lng, Float, :deep => true

    def city
      encode(@city)
    end

    def country
      encode(@country)
    end

    def region
      encode(@region)
    end

    private

    def encode(api_string)
      if api_string.respond_to?(:encode)
        api_string.encode("UTF-8")
      else
        Iconv.iconv('utf-8', 'windows-1251', api_string).first
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ipgeobase-0.1.1 lib/ipgeobase/ip_meta_data.rb