Class: FarsiFu::Convert
- Inherits:
-
Object
- Object
- FarsiFu::Convert
- Defined in:
- lib/farsifu/convert.rb
Instance Method Summary collapse
-
#initialize(number) ⇒ Convert
constructor
A new instance of Convert.
-
#to_english ⇒ Object
Returns a string which is the equivalent English number of a Persian number (in String).
-
#to_farsi ⇒ Object
Returns a string which is the equivalent Persian number of an English number (in String) accepts instances of String, Integer and Numeric classes (Fixnum,Bignum and floats are accepted).
- #to_s ⇒ Object
Constructor Details
#initialize(number) ⇒ Convert
Returns a new instance of Convert.
4 5 6 |
# File 'lib/farsifu/convert.rb', line 4 def initialize(number) @number = number end |
Instance Method Details
#to_english ⇒ Object
Returns a string which is the equivalent English number of a Persian number (in String)
Example:
"۱۲۳".to_english # => "123"
14 15 16 |
# File 'lib/farsifu/convert.rb', line 14 def to_english self.to_s.tr(PERSIAN_CHARS,ENGLISH_CHARS) end |
#to_farsi ⇒ Object
Returns a string which is the equivalent Persian number of an English number (in String) accepts instances of String, Integer and Numeric classes (Fixnum,Bignum and floats are accepted)
alias: to_persian
Example:
"123".to_farsi # => "۱۲۳"
"456".to_persian # => "۴۵۶"
789.to_farsi # => "۷۸۹"
27 28 29 |
# File 'lib/farsifu/convert.rb', line 27 def to_farsi self.to_s.tr(ENGLISH_CHARS,PERSIAN_CHARS) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/farsifu/convert.rb', line 31 def to_s @number.to_s end |