Sha256: 67458f6ed8587861a3ffdae224a943757914ffb6d0a8f5da52d6cb9b47eb530a

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8

require 'cldr-plurals/ruby-runtime/str_num'

module CldrPlurals
  module RubyRuntime
    class << self

      def build_args_for(num_str)
        num = StrNum.from_string(num_str)

        [
          n(num), i(num), f(num),
          t(num), v(num), w(num),
          e(num)
        ]
      end

      # absolute value of the source number (integer and decimals).
      def n(num)
        wrap(num).abs.strip.to_val
      end

      # integer digits of n.
      def i(num)
        wrap(num).apply_exp.int_val
      end

      # visible fractional digits in n, with trailing zeros.
      def f(num)
        wrap(num).apply_exp.frac_val.to_i
      end

      # visible fractional digits in n, without trailing zeros.
      def t(num)
        wrap(num).apply_exp.strip.frac_val.to_i
      end

      # number of visible fraction digits in n, with trailing zeros.
      def v(num)
        wrap(num).apply_exp.frac.length
      end

      # number of visible fraction digits in n, without trailing zeros.
      def w(num)
        wrap(num).apply_exp.strip.frac_val.length
      end

      def e(num)
        wrap(num).exp
      end

      private

      def wrap(str_or_num)
        return str_or_num if str_or_num.is_a?(StrNum)
        StrNum.from_string(str_or_num)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cldr-plurals-runtime-rb-1.1.0 lib/cldr-plurals/ruby_runtime.rb