Sha256: 9275aad6c483d124a4ede60209317e4846ff2be96b1713223bf2a44b8c7b330a

Contents?: true

Size: 854 Bytes

Versions: 9

Compression:

Stored size: 854 Bytes

Contents

module Europe
  # Countries
  module Countries
    # Reversed
    module Reversed
      def self.generate(country_value)
        COUNTRIES.each_with_object({}) do |(key, value), out|
          reverse_handle_value(out, key, value, country_value)
        end
      end

      def self.reverse_handle_value(out, key, value, country_value)
        if out[value[country_value.to_sym]]
          reverse_handle_array(out, key, value, country_value)
        else
          out[value[country_value.to_sym]] = key
        end
      end

      def self.reverse_handle_array(out, key, value, country_value)
        if out[value[country_value.to_sym]].is_a?(Array)
          out[value[country_value.to_sym]] << key
        else
          out[value[country_value.to_sym]] =
            [out[value[country_value.to_sym]], key]
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
europe-0.0.13 lib/europe/countries/reversed.rb
europe-0.0.12 lib/europe/countries/reversed.rb
europe-0.0.11 lib/europe/countries/reversed.rb
europe-0.0.10 lib/europe/countries/reversed.rb
europe-0.0.9 lib/europe/countries/reversed.rb
europe-0.0.8 lib/europe/countries/reversed.rb
europe-0.0.7 lib/europe/countries/reversed.rb
europe-0.0.6 lib/europe/countries/reversed.rb
europe-0.0.5 lib/europe/countries/reversed.rb