lib/ipgeobase/ip_meta_data.rb in ipgeobase-0.0.1 vs lib/ipgeobase/ip_meta_data.rb in ipgeobase-0.1.0

- old
+ new

@@ -1,27 +1,39 @@ -require 'iconv' +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 - Iconv.iconv('windows-1251', 'utf-8', @city).first + encode(@city) end def country - Iconv.iconv('windows-1251', 'utf-8', @country).first + encode(@country) end def region - Iconv.iconv('windows-1251', 'utf-8', @region).first + encode(@region) + end + + private + + def encode(api_string) + if api_string.respond_to?(:encode) + api_string.encode + else + Iconv.iconv('windows-1251', 'utf-8', api_string).first + end end end end