Class: GeezifyRb::Arabify

Inherits:
Object
  • Object
show all
Defined in:
lib/geezify-rb/arabify.rb

Overview

processing tools to convert Geeze numbers to arabic.

Constant Summary collapse

ERROR_MSG_CONSTRUCTOR =
'invalid input the string is not a geez number'
ERROR_MSG1 =
'invalid input to method convert_2digit'
ERROR_MSG3 =
'invalid input to method rollback'
NUMHASH =
Hash['፩' => 1,  '፪' => 2,  '፫' => 3,  '፬' => 4,
'፭' => 5,  '፮' => 6,  '፯' => 7,  '፰' => 8,
'፱' => 9,  '፲' => 10, '፳' => 20, '፴' => 30,
'፵' => 40, '፶' => 50, '፷' => 60, '፸' => 70,
'፹' => 80, '፺' => 90, ' ' => 0]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Arabify

Returns a new instance of Arabify.

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/geezify-rb/arabify.rb', line 17

def initialize(str)
  raise ArgumentError, ERROR_MSG_CONSTRUCTOR unless validinput?(str)

  @geezstr = str
end

Class Method Details

.arabify(str) ⇒ Object



23
24
25
# File 'lib/geezify-rb/arabify.rb', line 23

def self.arabify(str)
  new(str).arabify
end

Instance Method Details

#arabifyObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/geezify-rb/arabify.rb', line 27

def arabify
  preprocessed = rollback(@geezstr.gsub('፼', '፼ ')).split('፼')

  preprocessed
    .each_with_index
    .reduce(0) do |sum, (v, i)|
    sum + convert_upto10000(v.strip) *
          (10_000**(preprocessed.length - 1 - i))
  end
end