Class: FarsiFu::NumToWord
- Inherits:
-
Object
- Object
- FarsiFu::NumToWord
- Defined in:
- lib/farsifu/num_to_word.rb
Instance Method Summary collapse
-
#initialize(number, verbose = true) ⇒ NumToWord
constructor
A new instance of NumToWord.
-
#spell_farsi ⇒ Object
Spells a number in Persian accpets english numbers (in float,fixnum or string).
-
#spell_ordinal_farsi(second_type = false) ⇒ Object
Spells numbers in sequentional format.
Constructor Details
#initialize(number, verbose = true) ⇒ NumToWord
Returns a new instance of NumToWord.
6 7 8 9 10 11 |
# File 'lib/farsifu/num_to_word.rb', line 6 def initialize(number, verbose = true) @number = number.to_s @sign = check_for_sign @float = true if number.is_a? Float @verbose = verbose end |
Instance Method Details
#spell_farsi ⇒ Object
Spells a number in Persian accpets english numbers (in float,fixnum or string)
Example:
5678.spell_farsi # => "پنج هزار و ششصد و هفتاد و هشت"
3.22.spell_farsi # => "سه ممیز بیست و دو صدم"
19 20 21 22 23 24 25 |
# File 'lib/farsifu/num_to_word.rb', line 19 def spell_farsi if @float parse_and_spell_float else parse_and_spell_real_number end end |
#spell_ordinal_farsi(second_type = false) ⇒ Object
Spells numbers in sequentional format. If pass ‘true`, it will use the second format
Example:
1.spell_ordinal_farsi # => "اول"
121.spell_ordinal_farsi # => "صد و بیست و یکم"
2.spell_ordinal_farsi(true) # => "دومین"
2054.spell_ordinal_farsi(true) # => "دو هزار و پنجاه چهارمین"
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/farsifu/num_to_word.rb', line 34 def spell_ordinal_farsi(second_type = false) if second_type exceptions = {'0' => "صفر", '1' => "اولین", '3' => "سومین"} suffix = "مین" else exceptions = {'0' => "صفر", '1' => "اول", '3' => "سوم"} suffix = "م" end make_ordinal_spell(exceptions, suffix) end |