Sha256: 6810f5a5b873d0c347a3d909f2c93e86782f04bf5877f6d3464f488d9796528f

Contents?: true

Size: 858 Bytes

Versions: 4

Compression:

Stored size: 858 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.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

4 entries across 4 versions & 1 rubygems

Version Path
papla-0.1.1 lib/papla/backend.rb
papla-0.1.0 lib/papla/backend.rb
papla-0.0.5 lib/papla/backend.rb
papla-0.0.4 lib/papla/backend.rb