Sha256: 5df5528bda2bd7bfafd69a23a803ddb6b96b7070dbf72a7870b8ac7674c76c19

Contents?: true

Size: 873 Bytes

Versions: 2

Compression:

Stored size: 873 Bytes

Contents

require 'i18n'

I18n.load_path += Dir[File.expand_path('../locale/*', __FILE__)]

module Papla
  class Backend
    def zero
      translate(:zero)
    end

    def ones(index)
      translate(:ones)[index]
    end

    def tens(index)
      translate(:tens)[index]
    end

    def hundreds(index)
      translate(:hundreds)[index]
    end

    def rank(index, number)
      rule = pluralization_rule(number)
      rules = translate(:ranks)[index]
      rules[rule] || rules[rule.to_s]
    end

    def cents(basic_phrase, cents)
      cents = "%02d" % cents
      translate(:cents, basic_phrase: basic_phrase, cents: cents)
    end

    private

    def translate(message, options = {})
      options[:scope] = :papla
      I18n.translate(message, options)
    end

    def pluralization_rule(number)
      I18n.translate(:papla)[:pluralization][number]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
papla-0.2.0 lib/papla/backend.rb
papla-0.1.2 lib/papla/backend.rb