File: subdivision.rb

package info (click to toggle)
ruby-countries 4.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,196 kB
  • sloc: ruby: 2,085; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Sources
  module CLDR
    # Auxiliary Subdivision class to support loading Unicode CLDR data to update local files
    class Subdivision
      attr_reader :xml, :language_code
      def initialize(language_code:, xml:)
        @language_code = language_code
        @xml = xml
      end

      def text
        xml.text
      end

      def country_code
        type[0..1].upcase
      end

      def code
        type[2..-1].upcase
      end

      def type
        xml.attributes['type'].value.delete('-')
      end

      def to_h
        data = {}
        data['translations'] ||= {}
        data['translations'][language_code] = text
        data
      end
    end
  end
end