numerale 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/numerale/version.rb +1 -1
- data/lib/numerale.rb +113 -114
- metadata +3 -3
data/lib/numerale/version.rb
CHANGED
data/lib/numerale.rb
CHANGED
@@ -1,136 +1,135 @@
|
|
1
1
|
class Numerale
|
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
|
-
end
|
2
|
+
UNITS = {0 => "zero",
|
3
|
+
1 => "jeden",
|
4
|
+
2 => "dwa",
|
5
|
+
3 => "trzy",
|
6
|
+
4 => "cztery",
|
7
|
+
5 => "pięć",
|
8
|
+
6 => "sześć",
|
9
|
+
7 => "siedem",
|
10
|
+
8 => "osiem",
|
11
|
+
9 => "dziewięć",
|
12
|
+
10 => "dziesięć",
|
13
|
+
11 => "jedenaście",
|
14
|
+
12 => "dwanaście",
|
15
|
+
13 => "trzynaście",
|
16
|
+
14 => "czternaście",
|
17
|
+
15 => "piętnaście",
|
18
|
+
16 => "szesnaście",
|
19
|
+
17 => "siedemnaście",
|
20
|
+
18 => "osiemnaście",
|
21
|
+
19 => "dziewiętnaście",
|
22
|
+
20 => "dwadzieścia",
|
23
|
+
30 => 'trzydzieści',
|
24
|
+
40 => 'czterdzieści',
|
25
|
+
50 => 'pięćdziesiąt',
|
26
|
+
60 => 'sześćdziesiąt',
|
27
|
+
70 => 'siedemdziesiąt',
|
28
|
+
80 => 'osiemdziesiąt',
|
29
|
+
90 => 'dziewięćdziesiąt',
|
30
|
+
100 => "sto",
|
31
|
+
200 => "dwieście",
|
32
|
+
300 => "trzysta",
|
33
|
+
400 => "czterysta",
|
34
|
+
500 => "pięćset",
|
35
|
+
600 => 'sześćset',
|
36
|
+
700 => 'siedemset',
|
37
|
+
800 => 'osiemset',
|
38
|
+
900 => 'dziewięćset',
|
39
|
+
1000 => {1 => 'tysiąc', 2 => 'tysiące', 5 => 'tysięcy'},
|
40
|
+
1000000 => {1 => 'milion', 2 => 'miliony', 5 => 'milionów'},
|
41
|
+
1000000000 => {1 => 'miliard', 2 => 'miliardy', 5 => 'miliardów'}}
|
42
|
+
|
43
|
+
CURRENCIES = {
|
44
|
+
'PLN' => { 'full' => {1 => 'złoty', 2 => 'złote', 5 => 'złotych'}, 'frac' => {1 => 'grosz', 2 => 'grosze', 5 => 'groszy'} },
|
45
|
+
'USD' => { 'full' => {1 => 'dollar', 2 => 'dollars', 5 => 'dollars'}, 'frac' => {1 => 'cent', 2 => 'cents', 5 => 'cents'}}
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
def initialize(d)
|
50
|
+
number = d
|
51
|
+
precision = 10**2
|
52
|
+
number = [number.to_i, ((number * precision).round % precision).to_i]
|
53
|
+
|
54
|
+
decomposition = []
|
55
|
+
i = 0
|
56
|
+
number.each do |n|
|
57
|
+
decomposition[i] = {}
|
58
|
+
|
59
|
+
if n == 0
|
60
|
+
decomposition[i][1] = 0
|
61
|
+
else
|
62
|
+
pow = 10**9
|
63
|
+
count = n
|
64
|
+
|
65
|
+
while pow > 0 do
|
66
|
+
decomposition[i][pow] = count / pow
|
67
|
+
count %= pow
|
68
|
+
pow /= 10**3
|
70
69
|
end
|
71
|
-
i += 1
|
72
70
|
end
|
73
|
-
|
74
|
-
@number = decomposition
|
71
|
+
i += 1
|
75
72
|
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
@ones = 0
|
80
|
-
|
81
|
-
if number.include?(pow) && number[pow] > 0
|
82
|
-
hundreds = (number[pow] / 10**2) * 10**2
|
83
|
-
if (number[pow] % 10**2) < 20 && ((number[pow] % 10**2) > 10)
|
84
|
-
tens = (number[pow] % 10**2)
|
85
|
-
ones = 0
|
86
|
-
else
|
87
|
-
tens = ((number[pow] % 10**2) / 10) * 10
|
88
|
-
ones = number[pow] % 10
|
89
|
-
end
|
74
|
+
@number = decomposition
|
75
|
+
end
|
90
76
|
|
91
|
-
|
92
|
-
|
93
|
-
|
77
|
+
def expand_partial(number, pow)
|
78
|
+
result = ""
|
79
|
+
@ones = 0
|
80
|
+
|
81
|
+
if number.include?(pow) && number[pow] > 0
|
82
|
+
hundreds = (number[pow] / 10**2) * 10**2
|
83
|
+
if (number[pow] % 10**2) < 20 && ((number[pow] % 10**2) > 10)
|
84
|
+
tens = (number[pow] % 10**2)
|
85
|
+
ones = 0
|
86
|
+
else
|
87
|
+
tens = ((number[pow] % 10**2) / 10) * 10
|
88
|
+
ones = number[pow] % 10
|
89
|
+
end
|
94
90
|
|
95
|
-
|
96
|
-
|
91
|
+
result += "#{UNITS[hundreds]} " if hundreds > 0
|
92
|
+
result += "#{UNITS[tens]} " if tens > 0
|
93
|
+
result += "#{UNITS[ones]} " if ones > 0
|
97
94
|
|
98
|
-
|
99
|
-
|
100
|
-
@ones = ones
|
101
|
-
end
|
95
|
+
c = (hundreds > 0 || tens > 0) ? ones > 1 && ones < 5 ? 2 : 5 : ones == 1 ? 1 : ones < 5 ? 2 : 5
|
96
|
+
result += "#{UNITS[pow][c]} " if UNITS[pow].class == Hash
|
102
97
|
|
103
|
-
|
98
|
+
@hundreds = hundreds
|
99
|
+
@tens = tens
|
100
|
+
@ones = ones
|
104
101
|
end
|
105
102
|
|
106
|
-
|
107
|
-
|
103
|
+
return result
|
104
|
+
end
|
108
105
|
|
109
|
-
|
110
|
-
|
106
|
+
def expand(number, currency, ending)
|
107
|
+
result = ""
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
pow /= 10**3
|
115
|
-
end
|
109
|
+
pow = 10**9
|
110
|
+
ones = 0
|
116
111
|
|
112
|
+
while pow > 0
|
113
|
+
result += expand_partial(number, pow)
|
114
|
+
pow /= 10**3
|
115
|
+
end
|
117
116
|
|
118
|
-
if result.strip == "" && number[1] == 0
|
119
|
-
result += "#{UNITS[0]} "
|
120
|
-
end
|
121
117
|
|
122
|
-
|
123
|
-
result += "#{
|
118
|
+
if result.strip == "" && number[1] == 0
|
119
|
+
result += "#{UNITS[0]} "
|
124
120
|
end
|
125
121
|
|
122
|
+
c = @hundreds > 0 || @tens > 0 ? @ones > 1 && @ones < 5 ? 2 : 5 : @ones == 1 ? 1 : @ones < 5 ? 2 : 5
|
123
|
+
result += "#{CURRENCIES[currency][ending][c]}" if result.strip != ""
|
124
|
+
end
|
125
|
+
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
127
|
+
def to_text(currency = "PLN")
|
128
|
+
result = ""
|
129
|
+
result = "#{expand(@number[0], currency, 'full')}"
|
130
|
+
result += " " if result.strip != ""
|
131
|
+
result += "#{expand(@number[1], currency, 'frac')}"
|
132
|
+
puts result
|
134
133
|
end
|
135
134
|
end
|
136
135
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numerale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Piotr Debosz
|