plata 0.1.0
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/.gitignore +45 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/locales/en.plata.yml +54 -0
- data/lib/locales/es.plata.yml +56 -0
- data/lib/locales/pt.plata.yml +54 -0
- data/lib/plata/version.rb +3 -0
- data/lib/plata.rb +243 -0
- data/plata.gemspec +31 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f466fe3628907fb5f2b65c0263d8a6ab2f65e91a
|
4
|
+
data.tar.gz: 4378f402235023964cd626262fdb1746cc4e4fe0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b89e8477a53d2a2c6e24bafa502a1a5193b4d93b67defefac82618873e26dc8c2123c9785bf9fcf8d5a03e375947ae40ea5e63f37937d05175a242520c6925c5
|
7
|
+
data.tar.gz: e7253cab5cbcf5831b2ed465ea868ec1c26108974dd41cf75fa79b4c3be0d1885ed1135a3fd330df54da2cfcc7bd4b74ca66818bb106df5d71cd000d07d6b6db
|
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.gem
|
11
|
+
*.rbc
|
12
|
+
/.config
|
13
|
+
/coverage/
|
14
|
+
/InstalledFiles
|
15
|
+
/pkg/
|
16
|
+
/spec/reports/
|
17
|
+
/spec/examples.txt
|
18
|
+
/test/tmp/
|
19
|
+
/test/version_tmp/
|
20
|
+
/tmp/
|
21
|
+
|
22
|
+
## Specific to RubyMotion:
|
23
|
+
.dat*
|
24
|
+
.repl_history
|
25
|
+
build/
|
26
|
+
|
27
|
+
## Documentation cache and generated files:
|
28
|
+
/.yardoc/
|
29
|
+
/_yardoc/
|
30
|
+
/doc/
|
31
|
+
/rdoc/
|
32
|
+
|
33
|
+
## Environment normalization:
|
34
|
+
/.bundle/
|
35
|
+
/vendor/bundle
|
36
|
+
/lib/bundler/man/
|
37
|
+
|
38
|
+
# for a library or gem, you might want to ignore these files since the code is
|
39
|
+
# intended to run in multiple environments; otherwise, check them in:
|
40
|
+
# Gemfile.lock
|
41
|
+
# .ruby-version
|
42
|
+
# .ruby-gemset
|
43
|
+
|
44
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
45
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ga6ix
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Plata
|
2
|
+
|
3
|
+
Rails gem to describe a number in words for *English* and *Spanish*. For use english and spanish simply define:
|
4
|
+
|
5
|
+
I18n.locale = :en (English)
|
6
|
+
I18n.locale = :es (Espanish)
|
7
|
+
|
8
|
+
Ideal to be used to print in receipts.
|
9
|
+
|
10
|
+
## Install
|
11
|
+
|
12
|
+
Add the following line in to your Gemfile:
|
13
|
+
```ruby
|
14
|
+
gem 'plata'
|
15
|
+
```
|
16
|
+
|
17
|
+
Or from github:
|
18
|
+
```ruby
|
19
|
+
gem 'plata', :git => 'git://github.com/gedera/plata.git'
|
20
|
+
```
|
21
|
+
|
22
|
+
And from the command line run:
|
23
|
+
```console
|
24
|
+
$ bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Examples for return numbers in *english* and *spanish*:
|
30
|
+
```ruby
|
31
|
+
> 9736.humanize
|
32
|
+
"nine thousand seven hundred thirty six" (English)
|
33
|
+
"nueve mil setecientos treinta y seis" (Spanish)
|
34
|
+
```
|
35
|
+
```ruby
|
36
|
+
> 9736.45.humanize
|
37
|
+
"nine thousand seven hundred thirty six with 45/100" (English)
|
38
|
+
"nueve mil setecientos treinta y seis con 45/100" (Spanish)
|
39
|
+
```
|
40
|
+
|
41
|
+
Enjoy!!!
|
42
|
+
|
43
|
+
### Version
|
44
|
+
0.1.0
|
45
|
+
|
46
|
+
License
|
47
|
+
----
|
48
|
+
MIT
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plata.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "plata"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
en:
|
2
|
+
plata:
|
3
|
+
and: 'and'
|
4
|
+
zero: 'zero'
|
5
|
+
thousand: 'thousand'
|
6
|
+
conector:
|
7
|
+
with: 'with'
|
8
|
+
units:
|
9
|
+
one: 'one'
|
10
|
+
two: 'two'
|
11
|
+
three: 'three'
|
12
|
+
four: 'four'
|
13
|
+
five: 'five'
|
14
|
+
six: 'six'
|
15
|
+
seven: 'seven'
|
16
|
+
eight: 'eight'
|
17
|
+
nine: 'nine'
|
18
|
+
teens:
|
19
|
+
ten: 'ten'
|
20
|
+
eleven: 'eleven'
|
21
|
+
twelve: 'twelve'
|
22
|
+
thirteen: 'thirteen'
|
23
|
+
fourteen: 'fourteen'
|
24
|
+
fifteen: 'fifteen'
|
25
|
+
sixteen: 'sixteen'
|
26
|
+
seventeen: 'seventeen'
|
27
|
+
eighteen: 'eighteen'
|
28
|
+
nineteen: 'nineteen'
|
29
|
+
tens:
|
30
|
+
ten: 'ten'
|
31
|
+
twenty: 'twenty'
|
32
|
+
thirty: 'thirty'
|
33
|
+
forty: 'forthy'
|
34
|
+
fifty: 'fifty'
|
35
|
+
sixty: 'sixty'
|
36
|
+
seventy: 'seventy'
|
37
|
+
eighty: 'eighty'
|
38
|
+
ninety: 'ninety'
|
39
|
+
hundreds:
|
40
|
+
one_hundred: 'one hundred'
|
41
|
+
two_hundred: 'two hundred'
|
42
|
+
three_hundred: 'three hundred'
|
43
|
+
four_hundred: 'four hundred'
|
44
|
+
five_hundred: 'five hundred'
|
45
|
+
six_hundred: 'six hundred'
|
46
|
+
seven_hundred: 'seven hundred'
|
47
|
+
eight_hundred: 'eight hundred'
|
48
|
+
nine_hundred: 'nine hundred'
|
49
|
+
quantities:
|
50
|
+
mill: 'mill'
|
51
|
+
bill: 'bill'
|
52
|
+
trill: 'trill'
|
53
|
+
cuatrill: 'cuatrill'
|
54
|
+
quintill: 'quintill'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
es:
|
2
|
+
plata:
|
3
|
+
and: 'y'
|
4
|
+
zero: 'cero'
|
5
|
+
thousand: 'mil'
|
6
|
+
conector:
|
7
|
+
with: 'con'
|
8
|
+
and: 'y'
|
9
|
+
units:
|
10
|
+
one: 'uno'
|
11
|
+
two: 'dos'
|
12
|
+
three: 'tres'
|
13
|
+
four: 'cuatro'
|
14
|
+
five: 'cinco'
|
15
|
+
six: 'seis'
|
16
|
+
seven: 'siete'
|
17
|
+
eight: 'ocho'
|
18
|
+
nine: 'nueve'
|
19
|
+
teens:
|
20
|
+
ten: 'diez'
|
21
|
+
eleven: 'once'
|
22
|
+
twelve: 'doce'
|
23
|
+
thirteen: 'trece'
|
24
|
+
fourteen: 'catorce'
|
25
|
+
fifteen: 'quince'
|
26
|
+
sixteen: 'dieciseis'
|
27
|
+
seventeen: 'diecisiete'
|
28
|
+
eighteen: 'dieciocho'
|
29
|
+
nineteen: 'diecinueve'
|
30
|
+
tens:
|
31
|
+
ten: 'diez'
|
32
|
+
twenty: 'veinte'
|
33
|
+
thirty: 'treinta'
|
34
|
+
forty: 'cuarenta'
|
35
|
+
fifty: 'ciecuenta'
|
36
|
+
sixty: 'sesenta'
|
37
|
+
seventy: 'setenta'
|
38
|
+
eighty: 'ochenta'
|
39
|
+
ninety: 'noventa'
|
40
|
+
hundreds:
|
41
|
+
one_hundred: 'cien'
|
42
|
+
one_hundred_with: 'ciento'
|
43
|
+
two_hundred: 'doscientos'
|
44
|
+
three_hundred: 'trescientos'
|
45
|
+
four_hundred: 'cuatrocientos'
|
46
|
+
five_hundred: 'quinientos'
|
47
|
+
six_hundred: 'seiscientos'
|
48
|
+
seven_hundred: 'setecientos'
|
49
|
+
eight_hundred: 'ochocientos'
|
50
|
+
nine_hundred: 'novecientos'
|
51
|
+
quantities:
|
52
|
+
mill: 'milli'
|
53
|
+
bill: 'billi'
|
54
|
+
trill: 'trilli'
|
55
|
+
cuatrill: 'cuatrilli'
|
56
|
+
quintill: 'quintilli'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
pt:
|
2
|
+
plata:
|
3
|
+
and: 'e'
|
4
|
+
zero: 'zero'
|
5
|
+
thousand: 'mil'
|
6
|
+
conector:
|
7
|
+
with: 'com'
|
8
|
+
units:
|
9
|
+
one: 'um'
|
10
|
+
two: 'dois'
|
11
|
+
three: 'três'
|
12
|
+
four: 'quatro'
|
13
|
+
five: 'cinco'
|
14
|
+
six: 'seis'
|
15
|
+
seven: 'sete'
|
16
|
+
eight: 'oito'
|
17
|
+
nine: 'nove'
|
18
|
+
teens:
|
19
|
+
ten: 'dez'
|
20
|
+
eleven: 'onze'
|
21
|
+
twelve: 'doze'
|
22
|
+
thirteen: 'treze'
|
23
|
+
fourteen: 'catorze'
|
24
|
+
fifteen: 'quinze'
|
25
|
+
sixteen: 'dezesseis'
|
26
|
+
seventeen: 'dezessete'
|
27
|
+
eighteen: 'dezoito'
|
28
|
+
nineteen: 'dezenove'
|
29
|
+
tens:
|
30
|
+
ten: 'dez'
|
31
|
+
twenty: 'veinte'
|
32
|
+
thirty: 'trinta'
|
33
|
+
forty: 'quarenta'
|
34
|
+
fifty: 'cinquenta'
|
35
|
+
sixty: 'sessenta'
|
36
|
+
seventy: 'setenta'
|
37
|
+
eighty: 'oitenta'
|
38
|
+
ninety: 'noventa'
|
39
|
+
hundreds:
|
40
|
+
one_hundred: 'cem'
|
41
|
+
two_hundred: 'duzentos'
|
42
|
+
three_hundred: 'trezentos'
|
43
|
+
four_hundred: 'quatrocentos'
|
44
|
+
five_hundred: 'quinhentos'
|
45
|
+
six_hundred: 'seiscentos'
|
46
|
+
seven_hundred: 'setecentos'
|
47
|
+
eight_hundred: 'oitocentos'
|
48
|
+
nine_hundred: 'novecentos'
|
49
|
+
quantities:
|
50
|
+
mill: 'milhão'
|
51
|
+
bill: 'bilhão'
|
52
|
+
trill: 'trilhão'
|
53
|
+
cuatrill: 'mil bilhões'
|
54
|
+
quintill: 'quintilhões'
|
data/lib/plata.rb
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require "plata/version"
|
3
|
+
I18n.load_path += Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'locales', '*.yml')]
|
4
|
+
|
5
|
+
|
6
|
+
module Plata
|
7
|
+
module Numeric
|
8
|
+
def self.included(recipient)
|
9
|
+
recipient.extend(ClassMethods)
|
10
|
+
recipient.class_eval do
|
11
|
+
include InstanceMethods
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
|
20
|
+
def humanize_foo
|
21
|
+
return self.zero_string self.zero?
|
22
|
+
words = []
|
23
|
+
number, decimal = self.to_s.split(".")
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def humanize
|
28
|
+
|
29
|
+
words = []
|
30
|
+
|
31
|
+
number = self.to_f
|
32
|
+
|
33
|
+
if number.to_i == 0
|
34
|
+
words << self.zero_string
|
35
|
+
else
|
36
|
+
decimal = number.to_s.split(".")[1].nil? ? 0 : number.to_s.split(".")[1].to_i
|
37
|
+
number = number.to_s.split(".")[0]
|
38
|
+
|
39
|
+
number = number.rjust(33,'0').reverse
|
40
|
+
groups = number.scan(/.../)
|
41
|
+
|
42
|
+
words << number_to_words(groups[0].reverse)
|
43
|
+
|
44
|
+
(1..10).each do |number|
|
45
|
+
if groups[number].to_i > 0
|
46
|
+
case number.to_i
|
47
|
+
when 1,3,5,7,9
|
48
|
+
words << I18n.t("plata.thousand")
|
49
|
+
# words << "thousand" if I18n.locale == :en
|
50
|
+
# words << "mil" if I18n.locale == :es
|
51
|
+
# words << "mil" if I18n.locale == :pt
|
52
|
+
else
|
53
|
+
words << (groups[number].reverse.to_i > 1 ? "#{self.quantities[number]}" : "#{self.quantities[number]}") if I18n.locale == :en
|
54
|
+
words << (groups[number].reverse.to_i > 1 ? "#{self.quantities[number]}" : "#{self.quantities[number]}") if I18n.locale == :pt
|
55
|
+
words << (groups[number].reverse.to_i > 1 ? "#{self.quantities[number]}ones" : "#{self.quantities[number]}ón") if I18n.locale == :es
|
56
|
+
end
|
57
|
+
words << number_to_words(groups[number].reverse)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
return "#{words.reverse.join(' ')} #{conector} #{decimal}/100"
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def conector; I18n.t("plata.conector.with"); end
|
67
|
+
|
68
|
+
def and_string; I18n.t("plata.conector.and"); end
|
69
|
+
|
70
|
+
def zero_string; I18n.t("plata.conector.zero"); end
|
71
|
+
|
72
|
+
def units
|
73
|
+
_units = ["~"]
|
74
|
+
%w[ one two three four five six seven eight nine ].each do |unit|
|
75
|
+
_units << I18n.t("plata.units.#{unit}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
# def conector
|
79
|
+
# case I18n.locale
|
80
|
+
# when :en
|
81
|
+
# "with"
|
82
|
+
# when :es
|
83
|
+
# "con"
|
84
|
+
# when :pt
|
85
|
+
# "com"
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
|
89
|
+
# def and_string
|
90
|
+
# return "y" if I18n.locale == :es
|
91
|
+
# return "e" if I18n.locale == :pt
|
92
|
+
# end
|
93
|
+
|
94
|
+
# def zero_string
|
95
|
+
# case I18n.locale
|
96
|
+
# when :en
|
97
|
+
# "zero"
|
98
|
+
# when :es
|
99
|
+
# "cero"
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
|
103
|
+
def units
|
104
|
+
# 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
105
|
+
case I18n.locale
|
106
|
+
when :en
|
107
|
+
%w[ ~ one two three four five six seven eight nine ]
|
108
|
+
when :es
|
109
|
+
# %w[ ~ un dos tres cuatro cinco seis siete ocho nueve ]
|
110
|
+
%w[ ~ uno dos tres cuatro cinco seis siete ocho nueve ]
|
111
|
+
when :pt
|
112
|
+
%w[ ~ um dois três quatro cinco seis sete oito nove ]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def tens
|
117
|
+
# 10, 20, 30, 40, 50, 60, 70, 80, 90
|
118
|
+
case I18n.locale
|
119
|
+
when :en
|
120
|
+
%w[ ~ ten twenty thirty forty fifty sixty seventy eighty ninety ]
|
121
|
+
when :es
|
122
|
+
%w[ ~ diez veinte treinta cuarenta cincuenta sesenta setenta ochenta noventa ]
|
123
|
+
when :pt
|
124
|
+
%w[ ~ dez veinte trinta quarenta cinquenta sessenta setenta oitenta noventa ]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def hundreds
|
129
|
+
# 100, 200, 300, 400 , 500, 600, 700, 800, 900
|
130
|
+
case I18n.locale
|
131
|
+
when :en
|
132
|
+
[ 'hundred', 'one hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred', 'six hundred', 'seven hundred', 'eight hundred', 'nine hundred' ]
|
133
|
+
when :es
|
134
|
+
%w[ cien ciento doscientos trescientos cuatrocientos quinientos seiscientos setecientos ochocientos novecientos ]
|
135
|
+
when :pt
|
136
|
+
%w[ ~ cem duzentos trezentos quatrocentos quinhentos seiscentos setecentos oitocentos novecentos ]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def teens
|
141
|
+
# 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
142
|
+
case I18n.locale
|
143
|
+
when :en
|
144
|
+
%w[ ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen ]
|
145
|
+
when :es
|
146
|
+
%w[ diez once doce trece catorce quince dieciseis diecisiete dieciocho diecinueve ]
|
147
|
+
when :pt
|
148
|
+
%W[ dez onze doze treze catorze quinze dezesseis dezessete dezoito dezenove ]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def quantities
|
153
|
+
case I18n.locale
|
154
|
+
when :en
|
155
|
+
%w[ ~ ~ mill ~ bill ~ trill ~ cuatrill ~ quintill ~ ]
|
156
|
+
when :es
|
157
|
+
%w[ ~ ~ milli ~ billi ~ trilli ~ ]
|
158
|
+
when :pt
|
159
|
+
%[ ~ ~ milhão ~ bilhão ~ trilhão ~ mil bilhões ~ quintilhões ]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def number_to_words_foo(number)
|
164
|
+
text = []
|
165
|
+
hundreds = number[0].to_i
|
166
|
+
tens = number[1].to_i
|
167
|
+
units = number[2].to_i
|
168
|
+
|
169
|
+
if hundreds > 0
|
170
|
+
if hundreds == 1 && (tens + units == 0)
|
171
|
+
text << self.hundreds[0]
|
172
|
+
else
|
173
|
+
text << self.hundreds[hundreds]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
if tens > 0
|
178
|
+
case tens
|
179
|
+
when 1
|
180
|
+
text << (units == 0 ? self.tens[tens] : self.teens[units])
|
181
|
+
when 2
|
182
|
+
text << (units == 0 ? self.tens[tens] : "veinti#{self.units[units]}") if I18n.locale == :es
|
183
|
+
text << self.tens[tens] if I18n.locale == :en
|
184
|
+
text << "#{self.and_string} #{self.tens[tens]}" if I18n.locale == :pt
|
185
|
+
else
|
186
|
+
text << self.and_string if (I18n.locale == :pt and hundreds > 0)
|
187
|
+
text << self.tens[tens]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
def number_to_words(number)
|
195
|
+
|
196
|
+
hundreds = number[0,1].to_i
|
197
|
+
tens = number[1,1].to_i
|
198
|
+
units = number[2,1].to_i
|
199
|
+
|
200
|
+
text = []
|
201
|
+
|
202
|
+
if hundreds > 0
|
203
|
+
if hundreds == 1 && (tens + units == 0)
|
204
|
+
text << self.hundreds[0]
|
205
|
+
else
|
206
|
+
text << self.hundreds[hundreds]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
if tens > 0
|
211
|
+
case tens
|
212
|
+
when 1
|
213
|
+
text << (units == 0 ? self.tens[tens] : self.teens[units])
|
214
|
+
when 2
|
215
|
+
text << (units == 0 ? self.tens[tens] : "veinti#{self.units[units]}") if I18n.locale == :es
|
216
|
+
text << self.tens[tens] if I18n.locale == :en
|
217
|
+
text << "#{self.and_string} #{self.tens[tens]}" if I18n.locale == :pt
|
218
|
+
else
|
219
|
+
text << self.and_string if (I18n.locale == :pt and hundreds > 0)
|
220
|
+
text << self.tens[tens]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
if units > 0
|
225
|
+
if tens == 0
|
226
|
+
text << self.units[units]
|
227
|
+
elsif tens > 2
|
228
|
+
text << "#{self.and_string} #{self.units[units]}" if I18n.locale == :es
|
229
|
+
text << "#{self.and_string} #{self.units[units]}" if I18n.locale == :pt
|
230
|
+
text << self.units[units] if I18n.locale == :en
|
231
|
+
else
|
232
|
+
text << "#{self.and_string} #{self.units[units]}" if I18n.locale == :pt
|
233
|
+
text << self.units[units] if I18n.locale == :en
|
234
|
+
end
|
235
|
+
end
|
236
|
+
return text.join(' ')
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
Numeric.send :include, Plata::Numeric
|
data/plata.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'plata/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "plata"
|
8
|
+
spec.version = Plata::VERSION
|
9
|
+
spec.authors = ["ga6ix"]
|
10
|
+
spec.email = ["gab.edera@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Describe a number in words for English, Spanish and Portugues."
|
13
|
+
spec.description = "Describe a number in words for English, Spanish and Portugues."
|
14
|
+
spec.homepage = "https://github.com/gedera/plata"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ga6ix
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Describe a number in words for English, Spanish and Portugues.
|
42
|
+
email:
|
43
|
+
- gab.edera@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/locales/en.plata.yml
|
56
|
+
- lib/locales/es.plata.yml
|
57
|
+
- lib/locales/pt.plata.yml
|
58
|
+
- lib/plata.rb
|
59
|
+
- lib/plata/version.rb
|
60
|
+
- plata.gemspec
|
61
|
+
homepage: https://github.com/gedera/plata
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Describe a number in words for English, Spanish and Portugues.
|
84
|
+
test_files: []
|