Sha256: dd3d05d021111c9fe5f87f78fa583a70546bc82dd0674b698655dfb7caf6903c

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Localized
    class LocalizedNumber < LocalizedObject

      attr_reader :type, :format

      def initialize(obj, locale, options = {})
        @type = options[:type]
        @format = options[:format]
        super
      end

      class << self
        def types
          TwitterCldr::DataReaders::NumberDataReader.types
        end
      end

      types.each do |type|
        define_method "to_#{type}" do
          to_type(type)
        end
      end

      def to_s(options = {})
        TwitterCldr::DataReaders::NumberDataReader.new(locale, {
          type: @type,
          format: @format
        }).format_number(base_obj, options.merge(type: @type))
      end

      def plural_rule
        TwitterCldr::Formatters::Plurals::Rules.rule_for(base_obj, locale)
      end

      def spellout
        rbnf.format(
          base_obj, TwitterCldr::Formatters::Rbnf::RbnfFormatter::DEFAULT_SPELLOUT_OPTIONS
        )
      end

      def to_rbnf_s(group_name, rule_set_name)
        rbnf.format(base_obj, {
          rule_group: group_name,
          rule_set: rule_set_name
        })
      end

      def rbnf
        @rbnf ||= TwitterCldr::Formatters::Rbnf::RbnfFormatter.new(locale)
      end

      def to_unit
        TwitterCldr::Shared::Unit.create(base_obj, locale)
      end

      private

      def to_type(target_type)
        self.class.new(base_obj, locale, {
          type: target_type,
          format: @format
        })
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/localized/localized_number.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.5 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.4 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.3 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.2 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.1 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.4.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.3.1 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.3.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.2.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.1.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-4.0.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-3.6.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-3.5.0 lib/twitter_cldr/localized/localized_number.rb
twitter_cldr-3.4.0 lib/twitter_cldr/localized/localized_number.rb