Sha256: 263f138e545c3742af2aa81e1ac93a13e08c9ac7d1fff026262f2ab3d7a39d5a

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

module SubdivisionSelect
  module SubdivisionsHelper
    def self.get_subdivisions(alpha2)
      # The countries gem returns a hash, where:
      # the keys are the ISO 3166-2 subdivision two letter codes
      # and the value is a hash with two key/values:
      # - "name" is the most popular/most correct name
      # - "names" is an array of all the names
      if ISO3166::Country[alpha2].nil?
        {}
      else
        ISO3166::Country[alpha2].subdivisions.map { |k, v| [k, v["name"]] }.to_h
      end
    end

    def self.get_subdivisions_for_select(alpha2)
      get_subdivisions(alpha2).invert.to_a
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
subdivision_select-0.0.6 app/helpers/subdivision_select/subdivisions_helper.rb
subdivision_select-0.0.5 app/helpers/subdivision_select/subdivisions_helper.rb
subdivision_select-0.0.4 app/helpers/subdivision_select/subdivisions_helper.rb