Module: ToRupees

Included in:
Bignum, Fixnum, Float, String
Defined in:
lib/torupees.rb

Constant Summary collapse

NEPALI_NUMBERS =
{""=>"", 0=> "" , 1=> "" , 2=> "" , 3=> "" , 4=> "" , 5=> "" , 6=> "" , 7=>  "" , 8=> "", 9=> "" , 10=> "१०" , 11=> "११" , 12=> "१२" , 13=> "१३" , 14=> "१४" , 15=> "१५" , 16=> "१६" , 17=> "१७" , 18=> "१८" , 19=> "१९" , 20=> "२०" , 21=> "२१" , 22=> "२२" , 23=> "२३" , 24=> "२४" , 25=> "२५" , 26=> "२६" , 27=> "२७" , 28=> "२८" , 29=> "२९" , 30=> "३०" , 31=> "३१" , 32=> "३२" , 33=> "३३" , 34=> "३४" , 35=> "३५" , 36=> "३६" , 37=> "३७" , 38=> "३८" , 39=> "३९" , 40=> "४०" , 41=> "४१" , 42=> "४२" , 43=> "४३" , 44=> "४४" , 45=> "४५" , 46=> "४६" , 47=> "४७" , 48=> "४८" , 49=> "४९" , 50=> "५०" , 51=> "५१" , 52=> "५२" , 53=> "५३" , 54=> "५४" , 55=> "५५" , 56=> "५६" , 57=> "५७" , 58=> "५८" , 59=> "५९" , 60=> "६०" , 61=> "६१" , 62=> "६२" , 63=> "६३" , 64=> "६४" , 65=> "६५" , 66=> "६६" , 67=> "६७" , 68=> "६८" , 69=> "६९" , 70=> "७०" , 71=> "७१" , 72=> "७२" , 73=> "७३" , 74=> "७४" , 75=> "७५" , 76=> "७६" , 77=> "७७" , 78=> "७८" , 79=> "७९" , 80=> "८०" , 81=> "८१" , 82=> "८२" , 83=> "८३" , 84=> "८४" , 85=> "८५" , 86=> "८६" , 87=> "८७" , 88=> "८८" , 89=> "८९" , 90=> "९०" , 91=> "९१" , 92=> "९२" , 93=> "९३" , 94=> "९४" , 95=> "९५" , 96=> "९६" , 97=> "९७" , 98=> "९८" , 99=> "९९" , 100=> "१००" }

Instance Method Summary collapse

Instance Method Details

#check_sign(num) ⇒ Object



159
160
161
# File 'lib/torupees.rb', line 159

def check_sign(num)
    return num < 0 ? ([num.abs, '-']) : ([num, ''])
end

#to_rupaiyaObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/torupees.rb', line 23

def to_rupaiya
    
		string = self.to_s.gsub(/\s+/, "")
    
    decimalcheck =  string.index('.')
    if (decimalcheck != nil )
        #return "Decimal Number Detected" + decimalcheck.to_s
        paisa =  string[decimalcheck+1 .. decimalcheck+2 ]
        else
        p = false
        paisa = '0'
    end
    num = self.to_i
    num, sign = check_sign(num)
    #return "०" if num == 0
    return (sign + NEPALI_NUMBERS[num] + "" + paisa.to_i.to_rupaiya) if (num <= 100 && paisa.to_i != 0)
    #return (sign + NEPALI_NUMBERS[num]+ " |") if (num <=100 && paisa.to_i == 0)
    return "" if (num == 0 && paisa.to_i == 0)
    return (sign + NEPALI_NUMBERS[num]) if (num <=100 && paisa.to_i == 0)

    counter = 0
    result = []
    while num != 0
        if (num > 10000000000000000)
            return false
            

            elsif ((num / 1000000000000000) >= 1)
            test , remaining  = num.divmod(1000000000000000)
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999999999
              return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999999999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+ "."+ paisa).to_rupaiya )
            

            elsif ((num / 10000000000000) >= 1)
            test , remaining  = num.divmod(10000000000000)
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999999
              return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999999
              return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999999999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya )
            

            elsif ((num / 100000000000) >= 1)
            test , remaining  = num.divmod(100000000000)
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999
              return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999
              return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999999
              return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya )
            

            elsif ((num / 1000000000) >= 1)
            test , remaining  = num.divmod(1000000000)
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
            return ((sign + NEPALI_NUMBERS[test]) +",००,००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
             return ((sign + NEPALI_NUMBERS[test]) +",००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
              return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999
              return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999
              return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999999
              return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya )
            

            elsif ((num / 10000000) >= 1)
            test , remaining  = num.divmod(10000000)
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
              return ((sign + NEPALI_NUMBERS[test]) +",००,००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
              return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
              return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
              return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99999
              return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya )
            

            elsif ((num / 100000) >= 1)
            test , remaining  = num.divmod(100000)
            return ((sign + NEPALI_NUMBERS[test]) +",००,००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
             return ((sign + NEPALI_NUMBERS[test]) +",००,०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
              return ((sign + NEPALI_NUMBERS[test]) +",००,"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 999
               return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9999
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya )
          

          elsif ((num / 1000) >= 1)
            test , remaining  = num.divmod(1000)
            return ((sign + NEPALI_NUMBERS[test]) +",००"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 9
            return ((sign + NEPALI_NUMBERS[test]) +",०"+ (remaining.to_s+"."+paisa).to_rupaiya) if remaining <= 99
            return ((sign + NEPALI_NUMBERS[test]) +","+ (remaining.to_s+"."+paisa).to_rupaiya)
        
        end
        
        num, remaining = num.divmod(100)
      	#return (sign + NEPALI_NUMBERS[num] +"," + (remaining.to_s+"."+paisa).to_rupaiya )
      	if remaining <=9
      	temp_result = (sign + NEPALI_NUMBERS[num]) + "" + (NEPALI_NUMBERS[remaining])
      	else
      		temp_result = (sign + NEPALI_NUMBERS[num]) + (NEPALI_NUMBERS[remaining])
      	end

      	result = temp_result + "" + paisa.to_i.to_rupaiya
       # result = sign + result.reverse.join("").rstrip + "." + paisa.to_i.to_rupaiya
       #result = sign + result + "." + paisa.to_i.to_rupaiya
        return result 


end

end

#to_rupeesObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/torupees.rb', line 7

def to_rupees
  decimalcheck =  self.to_s.index('.')
  paisa =  self.to_s[decimalcheck+1 .. decimalcheck+2 ] if decimalcheck != nil

    if (self.to_rupaiya == false )
            result = "Impossible Number | Check your Input"
            elsif (self.to_i <=100 && decimalcheck == nil || paisa.to_i == 0)
            result = self.to_s.to_rupaiya + " ।०"
            else
            result = self.to_s.to_rupaiya
        end
        result = result.gsub("।० ।०",'।०')
        return result
end