class Datasets::CLDRPlurals

Constants

Locale
Rule

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/datasets/cldr-plurals.rb, line 18
    def initialize
      super()
      @metadata.id = "cldr-plurals"
      @metadata.name = "CLDR language plural rules"
      @metadata.url = "https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/plurals.xml"
      @metadata.licenses = ["Unicode-DFS-2016"]
      @metadata.description = <<~DESCRIPTION
        Language plural rules in Unicode Common Locale Data Repository.
        See also: https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_plural_rules.html
      DESCRIPTION
    end

Public Instance Methods

each(&block) click to toggle source
# File lib/datasets/cldr-plurals.rb, line 30
def each(&block)
  return to_enum(__method__) unless block_given?

  open_data do |input|
    catch do |abort_tag|
      listener = Listener.new(abort_tag, &block)
      parser = REXML::Parsers::StreamParser.new(input, listener)
      parser.parse
    end
  end
end

Private Instance Methods

open_data() { |input| ... } click to toggle source
# File lib/datasets/cldr-plurals.rb, line 43
def open_data
  data_path = cache_dir_path + "plurals.xml"
  unless data_path.exist?
    download(data_path, @metadata.url)
  end
  ::File.open(data_path) do |input|
    yield(input)
  end
end