number_to 0.7.0 → 0.7.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 +4 -4
- data/lib/data/number_words.yml +71 -0
- data/lib/modules/character_set.rb +39 -0
- data/lib/modules/number_words.rb +11 -63
- data/lib/number_to.rb +2 -2
- data/lib/number_to/fixnum.rb +3 -0
- metadata +4 -3
- data/lib/modules/alphabetics.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 391e3244b38ab6d4414f46def1338935e2d7bc3b
|
4
|
+
data.tar.gz: 78f884c179f44e5025319f8f1cd3cc0cc870d713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39ebd8705b73a33f7e0e54895a05e9b00a291683245f049fa2db17b898c00e0ab295cc05f9b7fdcaadd591701ac3d48f18d8f8c8bae9c820efba156b57eb1e89
|
7
|
+
data.tar.gz: 935a07d7185fb16eb97c6b878237492b10e11ceeb677fdf304e99e9ad42f455e3aefd8a4433e308b173de813d0ea91da7642a1cf55c8b05374481fc754535251
|
@@ -0,0 +1,71 @@
|
|
1
|
+
:words:
|
2
|
+
'0': zero
|
3
|
+
'1': one
|
4
|
+
'2': two
|
5
|
+
'3': three
|
6
|
+
'4': four
|
7
|
+
'5': five
|
8
|
+
'6': six
|
9
|
+
'7': seven
|
10
|
+
'8': eight
|
11
|
+
'9': nine
|
12
|
+
'10': ten
|
13
|
+
'11': eleven
|
14
|
+
'12': twelve
|
15
|
+
'13': thirteen
|
16
|
+
'14': fourteen
|
17
|
+
'15': fifteen
|
18
|
+
'16': sixteen
|
19
|
+
'17': seventeen
|
20
|
+
'18': eighteen
|
21
|
+
'19': nineteen
|
22
|
+
'20': twenty
|
23
|
+
'30': thirty
|
24
|
+
'40': forty
|
25
|
+
'50': fifty
|
26
|
+
'60': sixty
|
27
|
+
'70': seventy
|
28
|
+
'80': eighty
|
29
|
+
'90': ninety
|
30
|
+
:large_nums:
|
31
|
+
1: thousand
|
32
|
+
2: million
|
33
|
+
3: billion
|
34
|
+
4: trillion
|
35
|
+
:ordinals:
|
36
|
+
one: first
|
37
|
+
two: second
|
38
|
+
three: third
|
39
|
+
four: fourth
|
40
|
+
five: fifth
|
41
|
+
six: sixth
|
42
|
+
seven: seventh
|
43
|
+
eight: eighth
|
44
|
+
nine: ninth
|
45
|
+
One: First
|
46
|
+
Two: Second
|
47
|
+
Three: Third
|
48
|
+
Four: Fourth
|
49
|
+
Five: Fifth
|
50
|
+
Six: Sixth
|
51
|
+
Seven: Seventh
|
52
|
+
Eight: Eighth
|
53
|
+
Nine: Ninth
|
54
|
+
ten: tenth
|
55
|
+
twenty: twentieth
|
56
|
+
thirty: thirtieth
|
57
|
+
forty: fortieth
|
58
|
+
fifty: fiftieth
|
59
|
+
sixty: sixtieth
|
60
|
+
seventy: seventieth
|
61
|
+
eighty: eightieth
|
62
|
+
ninety: ninetieth
|
63
|
+
Ten: Tenth
|
64
|
+
Twenty: Twentieth
|
65
|
+
Thirty: Thirtieth
|
66
|
+
Forty: Fortieth
|
67
|
+
Fifty: Fiftieth
|
68
|
+
Sixty: Sixtieth
|
69
|
+
Seventy: Seventieth
|
70
|
+
Eighty: Eightieth
|
71
|
+
Ninety: Ninetieth
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CharacterSet
|
2
|
+
class CharacterSetConverter
|
3
|
+
attr_reader :characters, :options, :size
|
4
|
+
def initialize(characters, options = {})
|
5
|
+
@characters = characters
|
6
|
+
options[:repeat] = true unless options.include?(:repeat)
|
7
|
+
@options = options
|
8
|
+
@size = characters.size
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_characters(num)
|
12
|
+
num = num.to_i
|
13
|
+
repetition = num > size ? calc_repetition(num) : 1
|
14
|
+
real_num = num > size ? num % size : num
|
15
|
+
real_num = size if real_num == 0
|
16
|
+
char = characters[real_num - 1]
|
17
|
+
options[:repeat] ? char * repetition : char
|
18
|
+
end
|
19
|
+
|
20
|
+
def calc_repetition(num)
|
21
|
+
num % size == 0 ? num / size : (num / size) + 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ALPH = ("a" .. "z").to_a
|
26
|
+
ALPHABETTER = CharacterSetConverter.new(ALPH, {repeat: true})
|
27
|
+
|
28
|
+
def to_character_set(num, characters, options = {})
|
29
|
+
CharacterSetConverter.new(characters, options).to_characters(num)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_lower_alpha(num)
|
33
|
+
ALPHABETTER.to_characters(num)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_upper_alpha(num)
|
37
|
+
to_lower_alpha(num).upcase
|
38
|
+
end
|
39
|
+
end
|
data/lib/modules/number_words.rb
CHANGED
@@ -1,68 +1,16 @@
|
|
1
1
|
module NumberWords
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
'3' => 'three',
|
8
|
-
'4' => 'four',
|
9
|
-
'5' => 'five',
|
10
|
-
'6' => 'six',
|
11
|
-
'7' => 'seven',
|
12
|
-
'8' => 'eight',
|
13
|
-
'9' => 'nine',
|
14
|
-
'10' => 'ten',
|
15
|
-
'11' => 'eleven',
|
16
|
-
'12' => 'twelve',
|
17
|
-
'13' => 'thirteen',
|
18
|
-
'14' => 'fourteen',
|
19
|
-
'15' => 'fifteen',
|
20
|
-
'16' => 'sixteen',
|
21
|
-
'17' => 'seventeen',
|
22
|
-
'18' => 'eighteen',
|
23
|
-
'19' => 'nineteen',
|
24
|
-
'20' => 'twenty',
|
25
|
-
'30' => 'thirty',
|
26
|
-
'40' => 'forty',
|
27
|
-
'50' => 'fifty',
|
28
|
-
'60' => 'sixty',
|
29
|
-
'70' => 'seventy',
|
30
|
-
'80' => 'eighty',
|
31
|
-
'90' => 'ninety'
|
32
|
-
}
|
33
|
-
LARGE_NUMS = {
|
34
|
-
1 => 'thousand',
|
35
|
-
2 => 'million',
|
36
|
-
3 => 'billion',
|
37
|
-
4 => 'trillion'
|
38
|
-
}
|
39
|
-
ORDINALS = {
|
40
|
-
'one' => 'first',
|
41
|
-
'two' => 'second',
|
42
|
-
'three' => 'third',
|
43
|
-
'four' => 'fourth',
|
44
|
-
'five' => 'fifth',
|
45
|
-
'six' => 'sixth',
|
46
|
-
'seven' => 'seventh',
|
47
|
-
'eight' => 'eighth',
|
48
|
-
'nine' => 'ninth',
|
49
|
-
'One' => 'First',
|
50
|
-
'Two' => 'Second',
|
51
|
-
'Three' => 'Third',
|
52
|
-
'Four' => 'Fourth',
|
53
|
-
'Five' => 'Fifth',
|
54
|
-
'Six' => 'Sixth',
|
55
|
-
'Seven' => 'Seventh',
|
56
|
-
'Eight' => 'Eighth',
|
57
|
-
'Nine' => 'Ninth'
|
58
|
-
}
|
2
|
+
DATA_FILE = File.read(File.join(File.dirname(__FILE__), '../data/number_words.yml'))
|
3
|
+
DAT = YAML.load(DATA_FILE)
|
4
|
+
WORDS = DAT[:words]
|
5
|
+
LARGE_NUMS = DAT[:large_nums]
|
6
|
+
ORDINALS = DAT[:ordinals]
|
59
7
|
|
60
8
|
def to_words(num, options = {})
|
61
|
-
NumbersToWords.new(
|
9
|
+
NumbersToWords.new(options).to_words(num)
|
62
10
|
end
|
63
11
|
|
64
12
|
def to_word_ordinal(num, options = {})
|
65
|
-
text = NumbersToWords.new(
|
13
|
+
text = NumbersToWords.new(options).to_words(num)
|
66
14
|
change_last_word(text)
|
67
15
|
end
|
68
16
|
|
@@ -83,8 +31,7 @@ module NumberWords
|
|
83
31
|
attr_reader :hundred, :large_nums
|
84
32
|
DEFAULTS = {styled: false, case: 'lower', space: ' '}
|
85
33
|
|
86
|
-
def initialize(
|
87
|
-
@num = num.to_s
|
34
|
+
def initialize(options = {})
|
88
35
|
@options = DEFAULTS.merge(options)
|
89
36
|
set_style_opts
|
90
37
|
end
|
@@ -100,8 +47,8 @@ module NumberWords
|
|
100
47
|
large_nums
|
101
48
|
end
|
102
49
|
|
103
|
-
def to_words
|
104
|
-
arr = num.each_char.to_a
|
50
|
+
def to_words(num)
|
51
|
+
arr = num.to_s.each_char.to_a
|
105
52
|
groups = arr.reverse.each_slice(3).to_a
|
106
53
|
collector = words_for_groups(groups)
|
107
54
|
formatted_words(collector)
|
@@ -166,3 +113,4 @@ module NumberWords
|
|
166
113
|
end
|
167
114
|
end
|
168
115
|
end
|
116
|
+
|
data/lib/number_to.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'modules/roman_numerals'
|
2
|
-
require 'modules/alphabetics'
|
3
2
|
require 'modules/ordinals'
|
4
3
|
require 'modules/number_words'
|
4
|
+
require 'modules/character_set'
|
5
5
|
|
6
6
|
module NumberTo
|
7
7
|
extend RomanNumerals
|
8
|
-
extend Alphabetics
|
9
8
|
extend Ordinals
|
10
9
|
extend NumberWords
|
10
|
+
extend CharacterSet
|
11
11
|
end
|
data/lib/number_to/fixnum.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: number_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Corrigan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -74,10 +74,11 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- lib/number_to.rb
|
77
|
+
- lib/data/number_words.yml
|
77
78
|
- lib/modules/roman_numerals.rb
|
78
79
|
- lib/modules/number_words.rb
|
79
80
|
- lib/modules/ordinals.rb
|
80
|
-
- lib/modules/
|
81
|
+
- lib/modules/character_set.rb
|
81
82
|
- lib/number_to/fixnum.rb
|
82
83
|
homepage: http://www.scribenet.com
|
83
84
|
licenses:
|
data/lib/modules/alphabetics.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Alphabetics
|
2
|
-
def to_upper_alpha(num)
|
3
|
-
to_lower_alpha(num).upcase
|
4
|
-
end
|
5
|
-
|
6
|
-
def to_lower_alpha(num)
|
7
|
-
num_to_alph(num)
|
8
|
-
end
|
9
|
-
|
10
|
-
ALPH = ("a" .. "z").to_a
|
11
|
-
|
12
|
-
def num_to_alph(num)
|
13
|
-
num = num.to_i
|
14
|
-
repetition = num > 26 ? calc_repetition(num) : 1
|
15
|
-
real_num = num > 26 ? num % 26 : num
|
16
|
-
real_num = 26 if real_num == 0
|
17
|
-
ALPH[real_num - 1] * repetition
|
18
|
-
end
|
19
|
-
|
20
|
-
def calc_repetition(num)
|
21
|
-
num % 26 == 0 ? num / 26 : (num / 26) + 1
|
22
|
-
end
|
23
|
-
end
|