scottbarr-number_to_text 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.
- data/Manifest +7 -0
- data/README.rdoc +33 -0
- data/Rakefile +59 -0
- data/config.yml +4 -0
- data/init.rb +1 -0
- data/number_to_text.gemspec +32 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/number_test.rb +159 -0
- metadata +67 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= Number to Text
|
2
|
+
|
3
|
+
Convert an integer into text.
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
n = Number.new(119)
|
8
|
+
puts n.to_text # => "one-hundred-and-nineteen"
|
9
|
+
|
10
|
+
== License
|
11
|
+
|
12
|
+
(The MIT License)
|
13
|
+
|
14
|
+
Copyright (c) 2009 Global IT Creations Pte Ltd http://www.globalitcreations.com
|
15
|
+
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
18
|
+
in the Software without restriction, including without limitation the rights
|
19
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
20
|
+
copies of the Software, and to permit persons to whom the Software is
|
21
|
+
furnished to do so, subject to the following conditions:
|
22
|
+
|
23
|
+
The above copyright notice and this permission notice shall be included in
|
24
|
+
all copies or substantial portions of the Software.
|
25
|
+
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
32
|
+
THE SOFTWARE.
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'echoe'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
APP_NAME = "number-to-text"
|
8
|
+
APP_URL = "http://github.com/scottbarr/number-to-text/tree/master"
|
9
|
+
APP_DESCRIPTION = "Convert a number into text"
|
10
|
+
AUTHOR_NAME = "Scott Barr"
|
11
|
+
AUTHOR_EMAIL = "scottjbarr@gmail.com"
|
12
|
+
|
13
|
+
#
|
14
|
+
# Create a version for this build from the config.yml and the BUILD_NUMBER
|
15
|
+
# environment variable.
|
16
|
+
#
|
17
|
+
def get_version
|
18
|
+
# read the config file
|
19
|
+
config = open("config.yml") {|f| YAML.load(f)}
|
20
|
+
|
21
|
+
# build the version number
|
22
|
+
version_major = config["version"]["major"]
|
23
|
+
version_minor = config["version"]["minor"]
|
24
|
+
version_build = ENV["BUILD_NUMBER"] ||= "0"
|
25
|
+
"#{version_major}.#{version_minor}.#{version_build}"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::TestTask.new("test:units") { |t|
|
29
|
+
t.pattern = 'test/unit/*_test.rb'
|
30
|
+
t.verbose = true
|
31
|
+
t.warning = false
|
32
|
+
}
|
33
|
+
|
34
|
+
# setup the gem
|
35
|
+
Echoe.new(APP_NAME, get_version) do |p|
|
36
|
+
p.description = APP_DESCRIPTION
|
37
|
+
p.url = APP_URL
|
38
|
+
p.author = AUTHOR_NAME
|
39
|
+
p.email = AUTHOR_EMAIL
|
40
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
41
|
+
p.development_dependencies = []
|
42
|
+
end
|
43
|
+
|
44
|
+
# define a remove task method so the "test" task isn't breaking my stuff
|
45
|
+
Rake::TaskManager.class_eval do
|
46
|
+
def remove_task(task_name)
|
47
|
+
@tasks.delete(task_name.to_s)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# helper method to remove a task
|
52
|
+
def remove_task(task_name)
|
53
|
+
Rake.application.remove_task(task_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
# remove the original test task
|
57
|
+
remove_task :test
|
58
|
+
|
59
|
+
task :test => ["test:units"]
|
data/config.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'number'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{number_to_text}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Scott Barr"]
|
9
|
+
s.date = %q{2009-03-08}
|
10
|
+
s.description = %q{Convert a number into text}
|
11
|
+
s.email = %q{scottjbarr@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
13
|
+
s.files = ["config.yml", "init.rb", "Rakefile", "README.rdoc", "test/test_helper.rb", "test/unit/number_to_text_test.rb", "Manifest", "number_to_text.gemspec", "test/unit/number_test.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/scottbarr/number-to-text/tree/master}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Number_to_text", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{number_to_text}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Convert a number into text}
|
21
|
+
s.test_files = ["test/test_helper.rb", "test/unit/number_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class NumberTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@number = Number.new(123456789)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_integer_at
|
10
|
+
assert_equal 2, @number.integer_at(8)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_integer_in_group
|
14
|
+
assert_equal 789, @number.integer_in_group(0)
|
15
|
+
assert_equal 456, @number.integer_in_group(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_zero
|
19
|
+
assert Number.new(0).zero?
|
20
|
+
assert ! @number.zero?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_groups
|
24
|
+
assert_equal 789, @number.hundreds
|
25
|
+
assert_equal 456, @number.thousands
|
26
|
+
assert_equal 123, @number.millions
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_one
|
30
|
+
n = Number.new(1)
|
31
|
+
assert_equal 1, n.to_i
|
32
|
+
assert_equal 1, n.hundreds
|
33
|
+
assert_equal "one", n.to_text
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_ten
|
37
|
+
n = Number.new(10)
|
38
|
+
assert_equal 10, n.to_i
|
39
|
+
assert_equal 10, n.hundreds
|
40
|
+
assert_equal "ten", n.to_text
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_one_hundred
|
44
|
+
n = Number.new(100)
|
45
|
+
assert_equal 100, n.to_i
|
46
|
+
assert_equal 100, n.hundreds
|
47
|
+
assert_equal "one-hundred", n.to_text
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_ninety_eight
|
51
|
+
n = Number.new(98)
|
52
|
+
assert_equal 98, n.to_i
|
53
|
+
assert_equal 98, n.hundreds
|
54
|
+
assert_equal "ninety-eight", n.to_text
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_nine_hundred_and_eighty_seven
|
58
|
+
n = Number.new(987)
|
59
|
+
assert_equal 987, n.to_i
|
60
|
+
assert_equal 987, n.hundreds
|
61
|
+
assert_equal "nine-hundred-and-eighty-seven", n.to_text
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_nineteen
|
65
|
+
n = Number.new(19)
|
66
|
+
assert_equal 19, n.to_i
|
67
|
+
assert_equal 19, n.hundreds
|
68
|
+
assert_equal "nineteen", n.to_text
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_one_hundred_and_nineteen
|
72
|
+
n = Number.new(119)
|
73
|
+
assert_equal 119, n.to_i
|
74
|
+
assert_equal 119, n.hundreds
|
75
|
+
assert_equal "one-hundred-and-nineteen", n.to_text
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_two_hundred_and_one
|
79
|
+
n = Number.new(201)
|
80
|
+
assert_equal 201, n.to_i
|
81
|
+
assert_equal 201, n.hundreds
|
82
|
+
assert_equal "two-hundred-and-one", n.to_text
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_one_hundred_and_ninety
|
86
|
+
n = Number.new(190)
|
87
|
+
assert_equal 190, n.to_i
|
88
|
+
assert_equal 190, n.hundreds
|
89
|
+
assert_equal "one-hundred-and-ninety", n.to_text
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_one_thousand
|
93
|
+
n = Number.new(1000)
|
94
|
+
assert_equal 1000, n.to_i
|
95
|
+
assert_equal 1, n.thousands
|
96
|
+
assert_equal 0, n.hundreds
|
97
|
+
assert_equal "one-thousand", n.to_text
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_one_thousand_and_one
|
101
|
+
n = Number.new(1001)
|
102
|
+
assert_equal 1001, n.to_i
|
103
|
+
assert_equal 1, n.thousands
|
104
|
+
assert_equal 1, n.hundreds
|
105
|
+
assert_equal "one-thousand-and-one", n.to_text
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_one_hundred_thousand_and_one
|
109
|
+
n = Number.new(100001)
|
110
|
+
assert_equal 100001, n.to_i
|
111
|
+
assert_equal 100, n.thousands
|
112
|
+
assert_equal 1, n.hundreds
|
113
|
+
assert_equal "one-hundred-thousand-and-one", n.to_text
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_one_million_and_one
|
117
|
+
n = Number.new(1000001)
|
118
|
+
assert_equal 1000001, n.to_i
|
119
|
+
assert_equal 1, n.millions
|
120
|
+
assert_equal 0, n.thousands
|
121
|
+
assert_equal 1, n.hundreds
|
122
|
+
assert_equal "one-million-and-one", n.to_text
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_one_billion_and_one
|
126
|
+
n = Number.new(1000000001)
|
127
|
+
assert_equal 1000000001, n.to_i
|
128
|
+
assert_equal 1, n.billions
|
129
|
+
assert_equal 0, n.millions
|
130
|
+
assert_equal 0, n.thousands
|
131
|
+
assert_equal 1, n.hundreds
|
132
|
+
assert_equal "one-billion-and-one", n.to_text
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_one_trillion_and_one
|
136
|
+
n = Number.new(1000000000001)
|
137
|
+
assert_equal 1000000000001, n.to_i
|
138
|
+
assert_equal 1, n.trillions
|
139
|
+
assert_equal 0, n.billions
|
140
|
+
assert_equal 0, n.millions
|
141
|
+
assert_equal 0, n.thousands
|
142
|
+
assert_equal 1, n.hundreds
|
143
|
+
assert_equal "one-trillion-and-one", n.to_text
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_one_trillion_two_hundred_and_thirty_four_billion
|
147
|
+
n = Number.new(1234567891219)
|
148
|
+
assert_equal 1234567891219, n.to_i
|
149
|
+
assert_equal 1, n.trillions
|
150
|
+
assert_equal 234, n.billions
|
151
|
+
assert_equal 567, n.millions
|
152
|
+
assert_equal 891, n.thousands
|
153
|
+
assert_equal 219, n.hundreds
|
154
|
+
|
155
|
+
expected = "one-trillion-two-hundred-and-thirty-four-billion-five-hundred-and-sixty-seven-million-eight-hundred-and-ninety-one-thousand-and-two-hundred-and-nineteen"
|
156
|
+
assert_equal expected, n.to_text
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scottbarr-number_to_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Barr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-08 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Convert a number into text
|
17
|
+
email: scottjbarr@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- config.yml
|
26
|
+
- init.rb
|
27
|
+
- Rakefile
|
28
|
+
- README.rdoc
|
29
|
+
- test/test_helper.rb
|
30
|
+
- test/unit/number_to_text_test.rb
|
31
|
+
- Manifest
|
32
|
+
- number_to_text.gemspec
|
33
|
+
- test/unit/number_test.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/scottbarr/number-to-text/tree/master
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --line-numbers
|
39
|
+
- --inline-source
|
40
|
+
- --title
|
41
|
+
- Number_to_text
|
42
|
+
- --main
|
43
|
+
- README.rdoc
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "1.2"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: number_to_text
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: Convert a number into text
|
65
|
+
test_files:
|
66
|
+
- test/test_helper.rb
|
67
|
+
- test/unit/number_test.rb
|