Module: C12::KA

Includes:
ActionView::Helpers::NumberHelper
Defined in:
lib/c12-commons/ka.rb

Overview

This module is used for managing Georgian locale data.

Class Method Summary collapse

Class Method Details

.format_date(date, opts = {}) ⇒ Object

Format date.



43
44
45
46
# File 'lib/c12-commons/ka.rb', line 43

def self.format_date(date, opts = {})
  return nil unless date
  date.strftime("%d #{month(date, opts)} %Y")
end

.month(month, opts = {}) ⇒ Object

Returns the name of the month in georgian.

Month can be given as a number (January is 1) or as an instance of Time. Alternatively you can use month name in English (either short or long names). nil value for the argument returns nil as a month name.

If you need a short version of the month’s name, then use :format => :short in options.



31
32
33
34
35
36
37
38
39
40
# File 'lib/c12-commons/ka.rb', line 31

def self.month(month, opts = {})
  if month.respond_to? :month
    index = month.month
  elsif month.instance_of? Fixnum
    index = month % 12
  elsif month.instance_of? String
    index = MONTHS_EN[month.downcase] || MONTHS_EN_SHORT[month.downcase]
  end
  (opts[:format] == :short ? MONTHS_SHORT : MONTHS)[index - 1] if index
end

.number(number, opts = {}) ⇒ Object

Number formatter for georgian locale convensions.



49
50
51
# File 'lib/c12-commons/ka.rb', line 49

def self.number(number, opts = {})
  number_with_precision(number, :precision => opts[:precision] || 2, :delimiter => ' ', :separator => ',')
end

.tokenize(num, opts = {}) ⇒ Object

Tokenize number (in georgian).

Example usage:

C12::KA::tokenize(1) => ‘ერთი’ C12::KA::tokenize(2) => ‘ორი’

The maximum value for the argument is the value 999,999,999,999.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/c12-commons/ka.rb', line 61

def self.tokenize(num, opts = {})
  num_ge_0 = C12.nvl(num, 0).abs
  if num.instance_of? Fixnum
    token = tokenize_int_ge_0(num_ge_0)
  elsif num.instance_of? Float
    int_part = num_ge_0.floor
    dec_part = ((num_ge_0 - int_part) * 100).round
    token = [tokenize_int_ge_0(num_ge_0.floor), opts[:currency], dec_part, opts[:currency_minor]].compact.join(' ')
  end
  token = "მინუს #{token}" if num < 0
  token
end