Module: Zmanim::Util::HebrewNumericFormatter

Included in:
HebrewCalendar::HebrewDateFormatter, Limudim::LimudimFormatter
Defined in:
lib/zmanim/util/hebrew_numeric_formatter.rb

Constant Summary collapse

GERESH =
'׳'
GERSHAYIM =
'״'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#use_geresh_gershayimObject

Returns the value of attribute use_geresh_gershayim.



4
5
6
# File 'lib/zmanim/util/hebrew_numeric_formatter.rb', line 4

def use_geresh_gershayim
  @use_geresh_gershayim
end

Instance Method Details

#format_hebrew_number(number, include_thousands = false) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zmanim/util/hebrew_numeric_formatter.rb', line 13

def format_hebrew_number(number, include_thousands=false)
  raise ArgumentError unless (0..9999).include?(number)
  descriptors = {efes: 'אפס', alafim: 'אלפים'}
  one_glyphs = [''] + %w(א ב ג ד ה ו ז ח ט)
  ten_glyphs = [''] + %w(י כ ל מ נ ס ע פ צ)
  final_ten_glyphs = [''] + %w(י ך ל ם ן ס ע ף ץ)
  hundred_glyphs = [''] + %w(ק ר ש ת תק תר תש תת תתק)
  tav_taz_glyphs = %w(טו טז)

  return descriptors[:efes] if number == 0

  thousands, remainder = number.divmod(1000)
  hundreds, remainder = remainder.divmod(100)
  tens, ones = remainder.divmod(10)

  str = ''

  if number % 1000 == 0
    return add_geresh(one_glyphs[thousands]) + ' ' + descriptors[:alafim]
  elsif thousands > 0 && include_thousands
    str += add_geresh(one_glyphs[thousands]) + ' '
  end

  str += hundred_glyphs[hundreds]
  if tens == 1 and ones == 5
    str += tav_taz_glyphs[0]
  elsif tens == 1 and ones == 6
    str += tav_taz_glyphs[1]
  else
    if ones == 0 && hundreds != 0
      str += final_ten_glyphs[tens]
    else
      str += ten_glyphs[tens]
    end
    str += one_glyphs[ones]
  end

  if use_geresh_gershayim
    if [hundreds, tens, ones].select{|p| p > 0}.count == 1 && hundreds <= 4
      str += GERESH
    else
      str.insert(-2, GERSHAYIM)
    end
  end

  str
end

#initializeObject



9
10
11
# File 'lib/zmanim/util/hebrew_numeric_formatter.rb', line 9

def initialize
  @use_geresh_gershayim = true
end