Sha256: 90fc5b1759b80bd05da4e89b3e4ef606d7bc51660081ded30b8700afcb0ee48e

Contents?: true

Size: 863 Bytes

Versions: 91

Compression:

Stored size: 863 Bytes

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Formatters
    module Numbers
      class Fraction < Base
        attr_reader :format, :decimal, :precision

        def initialize(token, symbols = {})
          @format  = token ? token.value.split('.').pop : ''
          @decimal = symbols[:decimal] || '.'
          @precision = @format.length
        end

        def apply(fraction, options = {})
          precision = options[:precision] || self.precision
          if precision > 0
            decimal + interpolate(format(options), fraction, :left)
          else
            ''
          end
        end

        def format(options)
          precision = options[:precision] || self.precision
          precision ? '0' * precision : @format
        end
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 3 rubygems

Version Path
twitter_cldr-6.13.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.12.1 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.12.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.5 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.4 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.3 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.2 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.1 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.11.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.10.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.9.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.8.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.7.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.6.2 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.6.1 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.6.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.5.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.4.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.3.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb
twitter_cldr-6.2.0 lib/twitter_cldr/formatters/numbers/helpers/fraction.rb