Sha256: 1bc8322914c71fbe2088f2c83870fd228c7c6eff08b8203727c5e2253418cefb

Contents?: true

Size: 744 Bytes

Versions: 19

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

module Sources
  module Local
    # Auxiliary Subdivision class to support loading the local subdivision data to be updated with Unicode CLDR data
    class Subdivision
      attr_reader :code

      def initialize(code)
        @code = code
      end

      def load
        if File.exist?(file_path)
          YAML.load_file(file_path) || {}
        else
          {}
        end
      end

      def save(data)
        File.write(file_path, data.to_yaml)
      rescue StandardError
        puts "failed to read #{file}: #{$ERROR_INFO}"
      end

      def file_path
        "lib/countries/data/subdivisions/#{code}.yaml"
      end

      def self.load(code)
        new(code).load
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
countries-7.0.0 lib/countries/sources/local/subdivision.rb
countries-6.0.0 lib/countries/sources/local/subdivision.rb
countries-5.7.2 lib/countries/sources/local/subdivision.rb
countries-5.7.1 lib/countries/sources/local/subdivision.rb
countries-5.7.0 lib/countries/sources/local/subdivision.rb
countries-5.6.0 lib/countries/sources/local/subdivision.rb
countries-5.5.0 lib/countries/sources/local/subdivision.rb
countries-5.4.0 lib/countries/sources/local/subdivision.rb
countries-5.3.2 lib/countries/sources/local/subdivision.rb
countries-5.3.1 lib/countries/sources/local/subdivision.rb
countries-5.3.0 lib/countries/sources/local/subdivision.rb
countries-5.2.1 lib/countries/sources/local/subdivision.rb
countries-5.2.0 lib/countries/sources/local/subdivision.rb
countries-5.1.2 lib/countries/sources/local/subdivision.rb
countries-5.1.1 lib/countries/sources/local/subdivision.rb
countries-5.1.0 lib/countries/sources/local/subdivision.rb
countries-5.0.2 lib/countries/sources/local/subdivision.rb
countries-5.0.1 lib/countries/sources/local/subdivision.rb
countries-5.0.0 lib/countries/sources/local/subdivision.rb