Sha256: 404770e724b63fe4b04dfc042e4e6c97b83889bc4f4f791e0ba32ec3d4c56bb6

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

# encoding: UTF-8

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

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.0.1 lib/formatters/numbers/helpers/fraction.rb