Module: Parsi::Digits

Defined in:
lib/parsi-digits.rb

Constant Summary collapse

PARSI_DIGITS =
['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']

Class Method Summary collapse

Class Method Details

.en_delimiterObject



50
51
52
# File 'lib/parsi-digits.rb', line 50

def en_delimiter
  locale_delimiter locale: :en
end

.en_separatorObject



31
32
33
# File 'lib/parsi-digits.rb', line 31

def en_separator
  locale_separator locale: :en
end

.fa_delimiterObject



46
47
48
# File 'lib/parsi-digits.rb', line 46

def fa_delimiter
  locale_delimiter locale: :fa
end

.fa_separatorObject



27
28
29
# File 'lib/parsi-digits.rb', line 27

def fa_separator
  locale_separator locale: :fa
end

.locale_delimiter(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/parsi-digits.rb', line 35

def locale_delimiter options={}
  locale  = options[:locale]
  default = options[:default]
  default ||= (locale == :fa ? '٫' : ',')
  begin
    I18n.t(:'number.format.delimiter', default: default, locale: locale)
  rescue
    default
  end
end

.locale_separator(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/parsi-digits.rb', line 16

def locale_separator options={}
  locale  = options[:locale]
  default = options[:default]
  default ||= (locale == :fa ? '/' : '.')
  begin
    I18n.t(:'number.format.separator', default: default, locale: locale)
  rescue
    default
  end
end

.to_parsi(digit) ⇒ Object



8
9
10
# File 'lib/parsi-digits.rb', line 8

def to_parsi digit
  PARSI_DIGITS[digit.to_i] if digit =~ /[0-9]/
end

.to_western(digit) ⇒ Object



12
13
14
# File 'lib/parsi-digits.rb', line 12

def to_western digit
  PARSI_DIGITS.index digit if digit =~ /[۰-۹]/
end