module Sogou::Search::Api::Core::Regions

Constants

REGIONS_CODE

Public Instance Methods

convert_regions_to_string(results) click to toggle source

API document (translated by Google translate) says “regions” value can be either Interger[] or Integer from apihome.sogou.com/document/ss/doc9-1.jsp and apihome.sogou.com/document/ss/doc9-2.jsp,

# File lib/sogou/search/api/core/regions.rb, line 411
def convert_regions_to_string(results)
  if results.is_a?(Hash)
    regions = results['regions']
    if regions
      if regions.is_a?(Array)
        results['regions'] = regions.map { |r| REGIONS_CODE.fetch(r.to_i, r) }
      else
        results['regions'] = REGIONS_CODE.fetch(regions.to_i, regions)
      end
    end
  elsif results.is_a?(Array)
    results = results.map { |r| convert_regions_to_string(r) }
  end

  results
end