int_to_text_pl 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/int_to_text_pl.rb +151 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c496943a06124df28b18ef08b2903c1331d4770a82b48143ba6c05e073c3c127
|
4
|
+
data.tar.gz: 22864b958ebef5363167fe3e1bfc226ae184b364a33bf2e3fc1e9f9f87607475
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 826edf996a9d34cb9ee4db94de5f51ef5a9bbd76e4d177241b9db145240dcf53ec31b3e3a415992eaba149522a1780ad8854e6b524c03fea1c3cb90bfc821fa3
|
7
|
+
data.tar.gz: e4d2470c6f7f0ae702a867311a09b88c2e8deba80cf9d0f258907b41c1f71de26140fea3c6f974ca7ae3b94c499dc5f84bd01cece0063368ac4562accd702be3
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Liczby
|
2
|
+
|
3
|
+
JEDNOSTKI = {1 => "jeden", 2 => "dwa", 3 => "trzy", 4 => "cztery", 5 => "pięć", 6 => "sześć", 7 => "siedem", 8 => "osiem", 9 => "dziewięć"}
|
4
|
+
DZIESIATKI = {1 => "dziesięć", 2 => "dwadzieścia", 3 => "trzydzieści", 4 => "czterdzieści", 5 => "pięćdziesiąt", 6 => "sześćdziesiąt", 7 => "siedemdziesiąt", 8 => "osiemdziesiąt", 9 => "dziewięćdziesiąt"}
|
5
|
+
NASTKI = {1 => "jedenaście", 2 => "dwanaście", 3 => "trzynaście", 4 => "czternaście", 5 => "piętnaście", 6 => "szesnaście", 7 => "siedemnaście", 8 => "osiemnaście", 9 => "dziewiętnaście"}
|
6
|
+
SETKI = {1 => "sto", 2 => "dwieście", 3 => "trzysta", 4 => "czterysta", 5 => "pięćset", 6 => "sześćset", 7 => "siedemset", 8 => "osiemset", 9 => "dziewięćset"}
|
7
|
+
TYSIACE = {:one => "tysiąc", :few => "tysiące", :many => "tysięcy"}
|
8
|
+
MILIONY = {:one => "milion", :few => "miliony", :many => "milionów"}
|
9
|
+
MILIARDY = {:one => "miliard", :few => "miliardy", :many => "miliardow"}
|
10
|
+
|
11
|
+
def nastki
|
12
|
+
if (11..19).include?(self.to_s[-2..-1].to_i) then
|
13
|
+
NASTKI[self.to_s[-1].to_i]
|
14
|
+
else
|
15
|
+
if self.to_s[-1].to_i == 0 then
|
16
|
+
DZIESIATKI[self.to_s[-2].to_i]
|
17
|
+
else
|
18
|
+
"#{DZIESIATKI[self.to_s[-2].to_i]} #{JEDNOSTKI[self.to_s[-1].to_i]}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setki
|
24
|
+
if self.to_s[-2..-1].to_i == 0 then
|
25
|
+
SETKI[self.to_s[-3].to_i]
|
26
|
+
else
|
27
|
+
if self.to_s[-2].to_i == 0 then
|
28
|
+
"#{SETKI[self.to_s[-3].to_i]}#{nastki}"
|
29
|
+
else
|
30
|
+
"#{SETKI[self.to_s[-3].to_i]} #{nastki}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def tysiace
|
36
|
+
case self.to_s[0...-3].length
|
37
|
+
when 1
|
38
|
+
case self.to_s[0...-3].to_i
|
39
|
+
when 1
|
40
|
+
TYSIACE[:one]
|
41
|
+
when 2, 3, 4
|
42
|
+
TYSIACE[:few]
|
43
|
+
else
|
44
|
+
TYSIACE[:many]
|
45
|
+
end
|
46
|
+
else
|
47
|
+
if (10..19).include?(self.to_s[-5...-3].to_i)
|
48
|
+
TYSIACE[:many]
|
49
|
+
else
|
50
|
+
case self.to_s[-4...-3].to_i
|
51
|
+
when 2, 3, 4
|
52
|
+
TYSIACE[:few]
|
53
|
+
else
|
54
|
+
TYSIACE[:many]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def miliony
|
61
|
+
case self.to_s[0...-6].length
|
62
|
+
when 1
|
63
|
+
case self.to_s[0...-6].to_i
|
64
|
+
when 1
|
65
|
+
MILIONY[:one]
|
66
|
+
when 2, 3, 4
|
67
|
+
MILIONY[:few]
|
68
|
+
else
|
69
|
+
MILIONY[:many]
|
70
|
+
end
|
71
|
+
else
|
72
|
+
if (10..19).include?(self.to_s[-8...-6].to_i)
|
73
|
+
MILIONY[:many]
|
74
|
+
else
|
75
|
+
case self.to_s[-7...-6].to_i
|
76
|
+
when 2, 3, 4
|
77
|
+
MILIONY[:few]
|
78
|
+
else
|
79
|
+
MILIONY[:many]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def miliardy
|
86
|
+
case self.to_s[0...-9].length
|
87
|
+
when 1
|
88
|
+
case self.to_s[0...-9].to_i
|
89
|
+
when 1
|
90
|
+
MILIARDY[:one]
|
91
|
+
when 2, 3, 4
|
92
|
+
MILIARDY[:few]
|
93
|
+
else
|
94
|
+
MILIARDY[:many]
|
95
|
+
end
|
96
|
+
else
|
97
|
+
if (10..19).include?(self.to_s[-11...-9].to_i)
|
98
|
+
MILIARDY[:many]
|
99
|
+
else
|
100
|
+
case self.to_s[-10...-9].to_i
|
101
|
+
when 2, 3, 4
|
102
|
+
MILIARDY[:few]
|
103
|
+
else
|
104
|
+
MILIARDY[:many]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def rep_f
|
111
|
+
case self.to_s.length
|
112
|
+
when 1
|
113
|
+
JEDNOSTKI[self]
|
114
|
+
when 2
|
115
|
+
nastki
|
116
|
+
when 3
|
117
|
+
setki
|
118
|
+
else
|
119
|
+
raise "rep_f error"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def main_f
|
124
|
+
case self.to_s.length % 3 == 0 ? self.to_s.length / 3 - 1 : self.to_s.length / 3
|
125
|
+
when 0
|
126
|
+
if self == 0 then
|
127
|
+
"Zero"
|
128
|
+
else
|
129
|
+
rep_f.capitalize
|
130
|
+
end
|
131
|
+
when 1
|
132
|
+
"#{self.to_s[0...-3].to_i.rep_f} #{tysiace} #{self.to_s[-3..-1].to_i.rep_f}".capitalize.squeeze(' ').rstrip
|
133
|
+
when 2
|
134
|
+
"#{self.to_s[0...-6].to_i.rep_f} #{miliony} #{self.to_s[-6...-3].to_i.rep_f} #{tysiace if self.to_s[-6...-3].to_i != 0} #{self.to_s[-3..-1].to_i.rep_f}".capitalize.squeeze(' ').rstrip
|
135
|
+
when 3
|
136
|
+
"#{self.to_s[0...-9].to_i.rep_f} #{miliardy} #{self.to_s[-9...-6].to_i.rep_f} #{miliony if self.to_s[-9...-6].to_i != 0} #{self.to_s[-6...-3].to_i.rep_f} #{tysiace if self.to_s[-6...-3].to_i != 0} #{self.to_s[-3..-1].to_i.rep_f}".capitalize.squeeze(' ').rstrip
|
137
|
+
else
|
138
|
+
raise "Zbyt duża liczba -> main_f error"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
class Integer
|
145
|
+
include Liczby
|
146
|
+
|
147
|
+
def to_text_pl
|
148
|
+
main_f
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: int_to_text_pl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcin Rozmus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem allows you to change the integer number to Polish words by just
|
14
|
+
one method. You can use it to automating create invos or whatever you wanna.
|
15
|
+
email: marcin.rozmus97@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/int_to_text_pl.rb
|
21
|
+
homepage: https://rubygems.org/gems/int_to_text_pl
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata:
|
25
|
+
source_code_uri: https://github.com/MRozmus/int_to_text_pl
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.6
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Translates numbers to Polish words
|
45
|
+
test_files: []
|