Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/parsi_digits.rb

Instance Method Summary collapse

Instance Method Details

#has_parsi_digits?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/parsi_digits.rb', line 34

def has_parsi_digits?
  self =~ /[۰-۹]/
end

#to_fObject



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_fObject



47
# File 'lib/parsi_digits.rb', line 47

alias_method :western_to_f, :to_f

#western_to_iObject



38
# File 'lib/parsi_digits.rb', line 38

alias_method :western_to_i, :to_i

#with_parsi_digitsObject



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_digitsObject



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