Sha256: 29e2175ba12099509a168964744a01a0e75243c76a159c21e867d4414b5b45aa

Contents?: true

Size: 917 Bytes

Versions: 2

Compression:

Stored size: 917 Bytes

Contents

require_relative 'constants/fr'

module Humanize
  class Fr
    def humanize(number)
      iteration = 0
      parts = []
      until number.zero?
        number, remainder = number.divmod(1000)
        unless remainder.zero?
          add_grouping(parts, iteration, remainder)

          parts << SUB_ONE_GROUPING[remainder] unless exactly_one_thousand?(remainder, parts)
        end

        iteration += 1
      end

      parts
    end

    private

    def exactly_one_thousand?(remainder, parts)
      remainder == 1 && parts.last.to_s.strip == 'mille'
    end

    def plural_for_lots(remainder, word, iteration)
      if remainder > 1 && iteration >= 2
        "#{word}s"
      else
        word
      end
    end

    def add_grouping(parts, iteration, remainder)
      grouping = plural_for_lots(remainder, LOTS[iteration], iteration)
      return unless grouping

      parts << grouping
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
humanize-3.0.0 lib/humanize/locales/fr.rb
humanize-2.5.1 lib/humanize/locales/fr.rb