Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/parsi_digits.rb
Instance Method Summary collapse
- #has_parsi_digits? ⇒ Boolean
- #to_f ⇒ Object
- #to_i(base = 10) ⇒ Object
- #western_to_f ⇒ Object
- #western_to_i ⇒ Object
- #with_parsi_digits ⇒ Object
- #with_parsi_digits! ⇒ Object
- #with_western_digits ⇒ Object
- #with_western_digits! ⇒ Object
Instance Method Details
#has_parsi_digits? ⇒ Boolean
34 35 36 |
# File 'lib/parsi_digits.rb', line 34 def has_parsi_digits? self =~ /[۰-۹]/ end |
#to_f ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/parsi_digits.rb', line 48 def to_f if has_parsi_digits? with_western_digits.sub("/",".").western_to_f else western_to_f end end |
#to_i(base = 10) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/parsi_digits.rb', line 39 def to_i base=10 if has_parsi_digits? with_western_digits.western_to_i base else western_to_i base end end |
#western_to_f ⇒ Object
47 |
# File 'lib/parsi_digits.rb', line 47 alias_method :western_to_f, :to_f |
#western_to_i ⇒ Object
38 |
# File 'lib/parsi_digits.rb', line 38 alias_method :western_to_i, :to_i |
#with_parsi_digits ⇒ Object
18 19 20 |
# File 'lib/parsi_digits.rb', line 18 def with_parsi_digits gsub(/\d/) { |d| ParsiDigits.to_parsi d } end |
#with_parsi_digits! ⇒ Object
22 23 24 |
# File 'lib/parsi_digits.rb', line 22 def with_parsi_digits! gsub!(/\d/) { |d| ParsiDigits.to_parsi d } end |
#with_western_digits ⇒ Object
26 27 28 |
# File 'lib/parsi_digits.rb', line 26 def with_western_digits gsub(/[۰-۹]/) { |d| ParsiDigits.to_western d } end |
#with_western_digits! ⇒ Object
30 31 32 |
# File 'lib/parsi_digits.rb', line 30 def with_western_digits! gsub!(/[۰-۹]/) { |d| ParsiDigits.to_western d } end |