Sha256: ac4f8b6cc9079ed67928ceddf1409d4b04a2da09675fcbbf10a9253a641af06e

Contents?: true

Size: 717 Bytes

Versions: 3

Compression:

Stored size: 717 Bytes

Contents

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.open(file_path, 'w') { |f| f.write data.to_yaml }
      rescue
        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

3 entries across 3 versions & 1 rubygems

Version Path
countries-4.2.3 lib/countries/sources/local/subdivision.rb
countries-4.2.2 lib/countries/sources/local/subdivision.rb
countries-4.2.1 lib/countries/sources/local/subdivision.rb