roman 0.2.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/.index +72 -0
- data/HISTORY.md +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/lib/roman.rb +285 -0
- data/lib/roman.yml +72 -0
- data/test/fixnum_case.rb +13 -0
- data/test/roman_case.rb +59 -0
- data/test/string_case.rb +33 -0
- metadata +142 -0
data/.index
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
---
|
2
|
+
revision: 2013
|
3
|
+
type: ruby
|
4
|
+
sources:
|
5
|
+
- var
|
6
|
+
authors:
|
7
|
+
- name: Trans
|
8
|
+
email: transfire@gmail.com
|
9
|
+
organizations:
|
10
|
+
- name: Rubyworks
|
11
|
+
requirements:
|
12
|
+
- groups:
|
13
|
+
- build
|
14
|
+
development: true
|
15
|
+
name: detroit
|
16
|
+
- groups:
|
17
|
+
- build
|
18
|
+
development: true
|
19
|
+
name: ergo
|
20
|
+
- groups:
|
21
|
+
- test
|
22
|
+
development: true
|
23
|
+
name: rubytest-cli
|
24
|
+
- groups:
|
25
|
+
- test
|
26
|
+
development: true
|
27
|
+
name: lemon
|
28
|
+
- groups:
|
29
|
+
- test
|
30
|
+
development: true
|
31
|
+
name: ae
|
32
|
+
conflicts: []
|
33
|
+
alternatives: []
|
34
|
+
resources:
|
35
|
+
- type: home
|
36
|
+
uri: http://rubyworks.github.com/roman
|
37
|
+
label: Homepage
|
38
|
+
- type: code
|
39
|
+
uri: http://github.com/rubyworks/roman
|
40
|
+
label: Source Code
|
41
|
+
- type: docs
|
42
|
+
uri: http://rubydoc.info/gems/roman
|
43
|
+
label: Documentation
|
44
|
+
- type: wiki
|
45
|
+
uri: http://wiki.github.com/rubyworks/roman
|
46
|
+
label: User Guide
|
47
|
+
- type: bugs
|
48
|
+
uri: http://github.com/rubyworks/roman/issues
|
49
|
+
label: Issue Tracker
|
50
|
+
- type: mail
|
51
|
+
uri: http://groups.google.com/group/rubyworks-mailinglist
|
52
|
+
label: Mailing List
|
53
|
+
repositories:
|
54
|
+
- name: upstream
|
55
|
+
scm: git
|
56
|
+
uri: git://github.com/rubyworks/roman.git
|
57
|
+
categories: []
|
58
|
+
copyrights:
|
59
|
+
- holder: Rubyworks
|
60
|
+
year: '2007'
|
61
|
+
license: BSD-2-Clause
|
62
|
+
customs: []
|
63
|
+
paths:
|
64
|
+
lib:
|
65
|
+
- lib
|
66
|
+
created: '2010-03-02'
|
67
|
+
summary: Real Roman Numerals
|
68
|
+
title: Roman
|
69
|
+
version: 0.2.0
|
70
|
+
name: roman
|
71
|
+
description: RomanNumeral class for working with roman numerals in a native form.
|
72
|
+
date: '2013-03-09'
|
data/HISTORY.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# RELEASE HISTORY
|
2
|
+
|
3
|
+
|
4
|
+
## 0.2.0 / 2013-03-10
|
5
|
+
|
6
|
+
This release fixes the conversion of lower-case letters.
|
7
|
+
|
8
|
+
Changes:
|
9
|
+
|
10
|
+
* Fixed conversion of lower-case letters.
|
11
|
+
|
12
|
+
|
13
|
+
## 0.1.0 / 2010-10-10
|
14
|
+
|
15
|
+
Initialize release.
|
16
|
+
|
17
|
+
Changes:
|
18
|
+
|
19
|
+
* All of them ;)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(BSD-2-Clause License)
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
4
|
+
are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
1. Redistributions of source code must retain the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer.
|
8
|
+
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
14
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
16
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
17
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
18
|
+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
19
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
20
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Roman Numerals
|
2
|
+
|
3
|
+
[Website](http://rubyworks.github.com/roman) /
|
4
|
+
[Documentation](http://rubydoc.info/gems/roman/frames) /
|
5
|
+
[Report Issue](http://github.com/rubyworks/roman/issues) /
|
6
|
+
[Source Code](http://github.com/rubyworks/roman)
|
7
|
+
[](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
|
8
|
+
|
9
|
+
## STATUS
|
10
|
+
|
11
|
+
[](http://badge.fury.io/rb/roman)
|
12
|
+
[](https://travis-ci.org/rubyworks/roman)
|
13
|
+
|
14
|
+
|
15
|
+
## ABOUT
|
16
|
+
|
17
|
+
The Roman library provides a full-fledged Numeric subclass
|
18
|
+
for working in Roman Numerals.
|
19
|
+
|
20
|
+
In most cases this library is probably overkill. Instead,
|
21
|
+
[Ruby Facets](http://rubyworks.github.com/facets) provides Roman numeral
|
22
|
+
core extension methods for the `Integer` and `String` classes which are
|
23
|
+
likely to do everything that one really needs. However, the RomanNumeral
|
24
|
+
class has one advantage. It can be maniputated like any other Numeric
|
25
|
+
object without having to switch back and forth between representations.
|
26
|
+
Moreover, and probably most importantly, it makes an excellect example of
|
27
|
+
how to create a Numeric subclass in Ruby.
|
28
|
+
|
29
|
+
|
30
|
+
## HOW TO USE
|
31
|
+
|
32
|
+
We can create Roman numerals via the usual instantiation.
|
33
|
+
|
34
|
+
RomanNumeral.new(1) #=> #<RomanNumeral:0x7f10e378ad48 @i=1>
|
35
|
+
|
36
|
+
But to make it easier the Integer class is extended with #to_roman.
|
37
|
+
|
38
|
+
1.to_roman #=> #<RomanNumeral:0x7f10e378ad48 @i=1>
|
39
|
+
|
40
|
+
Roman numerals can also be formed from their String represnetation.
|
41
|
+
|
42
|
+
RomanNumeral.new('I') #=> #<RomanNumeral:0x7f10e378ad48 @i=1>
|
43
|
+
|
44
|
+
'I'.to_roman #=> #<RomanNumeral:0x7f10e378ad48 @i=1>
|
45
|
+
|
46
|
+
Because +RomanNumeral+ is a full-fledged subclass of Numeric,
|
47
|
+
we can work with them like we can an Integer.
|
48
|
+
|
49
|
+
a = 2.to_roman #=> #<RomanNumeral:0x7f10e378ad48 @i=2>
|
50
|
+
b = 3.to_roman #=> #<RomanNumeral:0x7f10e378ad48 @i=3>
|
51
|
+
r = a + b #=> #<RomanNumeral:0x7f10e378ad48 @i=5>
|
52
|
+
|
53
|
+
When we want to see the actual Romanized figure, we simple
|
54
|
+
call #to_s.
|
55
|
+
|
56
|
+
r.to_s #=> "IV"
|
57
|
+
|
58
|
+
|
59
|
+
## HOW TO INSTALL
|
60
|
+
|
61
|
+
Using RubyGems:
|
62
|
+
|
63
|
+
gem install roman
|
64
|
+
|
65
|
+
|
66
|
+
## COPYRIGHT & LICENSE
|
67
|
+
|
68
|
+
Copyright (c) 2007 Rubyworks
|
69
|
+
|
70
|
+
Roman is destributed under the terms of the
|
71
|
+
[BSD-2-Clause](http://spdx.org/license/BSD-2-Clause) license.
|
72
|
+
|
73
|
+
Please see LICENSE.txt file for details.
|
data/lib/roman.rb
ADDED
@@ -0,0 +1,285 @@
|
|
1
|
+
# Work with Roman numerals just like normal Integers.
|
2
|
+
class RomanNumeral < Numeric
|
3
|
+
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
# The largest integer representable as a roman
|
7
|
+
# numerable by this module.
|
8
|
+
MAX = 3999
|
9
|
+
|
10
|
+
# Taken from O'Reilly's Perl Cookbook 6.23. Regular Expression Grabbag.
|
11
|
+
REGEXP = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i
|
12
|
+
|
13
|
+
#
|
14
|
+
ROMAN_VALUES_ASSOC = [
|
15
|
+
["M", 1000],
|
16
|
+
["CM", 900],
|
17
|
+
["D", 500],
|
18
|
+
["CD", 400],
|
19
|
+
["C", 100],
|
20
|
+
["XC", 90],
|
21
|
+
["L", 50],
|
22
|
+
["XL", 40],
|
23
|
+
["X", 10],
|
24
|
+
["IX", 9],
|
25
|
+
["V", 5],
|
26
|
+
["IV", 4],
|
27
|
+
["I", 1]
|
28
|
+
]
|
29
|
+
|
30
|
+
#
|
31
|
+
ROMAN_VALUES = ROMAN_VALUES_ASSOC.inject({}){ |h,(r,a)| h[r] = a; h }
|
32
|
+
|
33
|
+
#
|
34
|
+
def self.from_integer(int)
|
35
|
+
#return nil if integer > MAX
|
36
|
+
return "-#{(-int).roman}" if int < 0
|
37
|
+
return "" if int == 0
|
38
|
+
ROMAN_VALUES_ASSOC.each do |(i, v)|
|
39
|
+
return(i + from_integer(int-v)) if v <= int
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
def self.to_integer(roman)
|
45
|
+
#return nil unless roman_string.is_roman_numeral?
|
46
|
+
last = roman[-1,1].upcase
|
47
|
+
roman.reverse.split('').inject(0) do |result, c|
|
48
|
+
c = c.upcase
|
49
|
+
if ROMAN_VALUES[c] < ROMAN_VALUES[last]
|
50
|
+
result -= ROMAN_VALUES[c]
|
51
|
+
else
|
52
|
+
last = c
|
53
|
+
result += ROMAN_VALUES[c]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns true if +string+ is a roman numeral.
|
59
|
+
def self.is_roman_numeral?(string)
|
60
|
+
REGEXP =~ string
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Create a new instance from an Integer, String
|
65
|
+
# or other RomanNumeral.
|
66
|
+
def initialize(val)
|
67
|
+
case val
|
68
|
+
when String
|
69
|
+
@i = self.class.to_integer(val)
|
70
|
+
@s = val.frozen? ? val : val.dup.freeze
|
71
|
+
when Numeric
|
72
|
+
@i = val.to_i
|
73
|
+
else
|
74
|
+
raise ArgumentError, 'Cannot convert %p' % val
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# hash code calculation
|
79
|
+
|
80
|
+
def hash
|
81
|
+
@i.hash
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
def to_s
|
86
|
+
@s ||= self.class.from_integer(@i)
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
def to_num ; @i ; end
|
91
|
+
|
92
|
+
#
|
93
|
+
def to_i ; @i ; end
|
94
|
+
|
95
|
+
#
|
96
|
+
def to_int ; @i ; end
|
97
|
+
|
98
|
+
#
|
99
|
+
def to_arabic ; @i ; end
|
100
|
+
|
101
|
+
#
|
102
|
+
def to_roman
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
def eql?(num)
|
108
|
+
self.class.equal?(num.class) && @i == num.to_i
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
def ==(num)
|
113
|
+
@i == num.to_num
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
def coerce(o)
|
118
|
+
[self.class.new(o.to_int), self]
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
def <=>(o)
|
123
|
+
case o
|
124
|
+
when Numeric
|
125
|
+
@i <=> o.to_num
|
126
|
+
else
|
127
|
+
a, b = o.coerce(self)
|
128
|
+
a <=> b
|
129
|
+
end rescue nil
|
130
|
+
end
|
131
|
+
|
132
|
+
# various tests that Fixnum also has
|
133
|
+
|
134
|
+
def zero?
|
135
|
+
@i.zero?
|
136
|
+
end
|
137
|
+
|
138
|
+
def nonzero?
|
139
|
+
@i.nonzero?
|
140
|
+
end
|
141
|
+
|
142
|
+
def odd?
|
143
|
+
@i.odd?
|
144
|
+
end
|
145
|
+
|
146
|
+
def even?
|
147
|
+
@i.even?
|
148
|
+
end
|
149
|
+
|
150
|
+
def between?(a, b)
|
151
|
+
@i.between? a, b
|
152
|
+
end
|
153
|
+
|
154
|
+
def integer?
|
155
|
+
true
|
156
|
+
end
|
157
|
+
|
158
|
+
def real?
|
159
|
+
true
|
160
|
+
end
|
161
|
+
|
162
|
+
def +@
|
163
|
+
self
|
164
|
+
end
|
165
|
+
|
166
|
+
def -@
|
167
|
+
self.class.new(-@i)
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
def +(o)
|
172
|
+
if Numeric === o
|
173
|
+
self.class.new(@i + o.to_num)
|
174
|
+
else
|
175
|
+
a, b = o.coerce(self)
|
176
|
+
a + b
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
def -(o)
|
182
|
+
if Numeric === o
|
183
|
+
self.class.new(@i - o.to_num)
|
184
|
+
else
|
185
|
+
a, b = o.coerce(self)
|
186
|
+
a - b
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
def *(o)
|
192
|
+
if Numeric === o
|
193
|
+
self.class.new(@i * o.to_num)
|
194
|
+
else
|
195
|
+
a, b = o.coerce(self)
|
196
|
+
a * b
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
def /(o)
|
202
|
+
if Numeric === o
|
203
|
+
self.class.new(@i / o.to_num)
|
204
|
+
else
|
205
|
+
a, b = o.coerce(self)
|
206
|
+
a / b
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def **(o)
|
211
|
+
if Numeric === o
|
212
|
+
self.class.new(@i / o.to_num)
|
213
|
+
else
|
214
|
+
a, b = o.coerce(self)
|
215
|
+
a / b
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def <<(o)
|
220
|
+
self.class.new(@i << o.to_int)
|
221
|
+
end
|
222
|
+
|
223
|
+
def >>(o)
|
224
|
+
self.class.new(@i >> o.to_int)
|
225
|
+
end
|
226
|
+
|
227
|
+
# bit operators
|
228
|
+
|
229
|
+
def &(o)
|
230
|
+
self.class.new(@i & o.to_int)
|
231
|
+
end
|
232
|
+
|
233
|
+
def |(o)
|
234
|
+
self.class.new(@i | o.to_int)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Freeze
|
238
|
+
def freeze
|
239
|
+
to_s
|
240
|
+
super
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
class Integer
|
247
|
+
|
248
|
+
#
|
249
|
+
def self.from_roman(roman)
|
250
|
+
RomanNumeral.to_integer(roman)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Converts this integer to a roman numeral.
|
254
|
+
def to_roman
|
255
|
+
RomanNumeral.new(self)
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
class String
|
262
|
+
|
263
|
+
# Considers string a roman numeral numeral,
|
264
|
+
# and converts it to the corresponding integer.
|
265
|
+
def to_roman
|
266
|
+
RomanNumeral.new(self)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Returns true if a valid roman numeral.
|
270
|
+
def is_roman_numeral?
|
271
|
+
RomanNumeral.is_roman_numeral?(self)
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
class Numeric
|
278
|
+
|
279
|
+
#
|
280
|
+
def to_num
|
281
|
+
self
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
data/lib/roman.yml
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
---
|
2
|
+
revision: 2013
|
3
|
+
type: ruby
|
4
|
+
sources:
|
5
|
+
- var
|
6
|
+
authors:
|
7
|
+
- name: Trans
|
8
|
+
email: transfire@gmail.com
|
9
|
+
organizations:
|
10
|
+
- name: Rubyworks
|
11
|
+
requirements:
|
12
|
+
- groups:
|
13
|
+
- build
|
14
|
+
development: true
|
15
|
+
name: detroit
|
16
|
+
- groups:
|
17
|
+
- build
|
18
|
+
development: true
|
19
|
+
name: ergo
|
20
|
+
- groups:
|
21
|
+
- test
|
22
|
+
development: true
|
23
|
+
name: rubytest-cli
|
24
|
+
- groups:
|
25
|
+
- test
|
26
|
+
development: true
|
27
|
+
name: lemon
|
28
|
+
- groups:
|
29
|
+
- test
|
30
|
+
development: true
|
31
|
+
name: ae
|
32
|
+
conflicts: []
|
33
|
+
alternatives: []
|
34
|
+
resources:
|
35
|
+
- type: home
|
36
|
+
uri: http://rubyworks.github.com/roman
|
37
|
+
label: Homepage
|
38
|
+
- type: code
|
39
|
+
uri: http://github.com/rubyworks/roman
|
40
|
+
label: Source Code
|
41
|
+
- type: docs
|
42
|
+
uri: http://rubydoc.info/gems/roman
|
43
|
+
label: Documentation
|
44
|
+
- type: wiki
|
45
|
+
uri: http://wiki.github.com/rubyworks/roman
|
46
|
+
label: User Guide
|
47
|
+
- type: bugs
|
48
|
+
uri: http://github.com/rubyworks/roman/issues
|
49
|
+
label: Issue Tracker
|
50
|
+
- type: mail
|
51
|
+
uri: http://groups.google.com/group/rubyworks-mailinglist
|
52
|
+
label: Mailing List
|
53
|
+
repositories:
|
54
|
+
- name: upstream
|
55
|
+
scm: git
|
56
|
+
uri: git://github.com/rubyworks/roman.git
|
57
|
+
categories: []
|
58
|
+
copyrights:
|
59
|
+
- holder: Rubyworks
|
60
|
+
year: '2007'
|
61
|
+
license: BSD-2-Clause
|
62
|
+
customs: []
|
63
|
+
paths:
|
64
|
+
lib:
|
65
|
+
- lib
|
66
|
+
created: '2010-03-02'
|
67
|
+
summary: Real Roman Numerals
|
68
|
+
title: Roman
|
69
|
+
version: 0.2.0
|
70
|
+
name: roman
|
71
|
+
description: RomanNumeral class for working with roman numerals in a native form.
|
72
|
+
date: '2013-03-09'
|
data/test/fixnum_case.rb
ADDED
data/test/roman_case.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'roman'
|
2
|
+
|
3
|
+
TestCase RomanNumeral do
|
4
|
+
|
5
|
+
Method :to_s do
|
6
|
+
test "one to three" do
|
7
|
+
1.to_roman.to_s.assert == 'I'
|
8
|
+
2.to_roman.to_s.assert == 'II'
|
9
|
+
3.to_roman.to_s.assert == 'III'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Method :to_s do
|
14
|
+
test "four" do
|
15
|
+
4.to_roman.to_s.assert == 'IV'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Method :to_s do
|
20
|
+
test "five to eight" do
|
21
|
+
5.to_roman.to_s.assert == 'V'
|
22
|
+
6.to_roman.to_s.assert == 'VI'
|
23
|
+
7.to_roman.to_s.assert == 'VII'
|
24
|
+
8.to_roman.to_s.assert == 'VIII'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Method :to_s do
|
29
|
+
test "nine" do
|
30
|
+
9.to_roman.to_s.assert == 'IX'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Method :to_s do
|
35
|
+
test "ten to thriteen" do
|
36
|
+
10.to_roman.to_s.assert == 'X'
|
37
|
+
11.to_roman.to_s.assert == 'XI'
|
38
|
+
12.to_roman.to_s.assert == 'XII'
|
39
|
+
13.to_roman.to_s.assert == 'XIII'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Method :to_s do
|
44
|
+
test "fourteen plus" do
|
45
|
+
14.to_roman.to_s.assert == 'XIV'
|
46
|
+
15.to_roman.to_s.assert == 'XV'
|
47
|
+
16.to_roman.to_s.assert == 'XVI'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Method :+ do
|
52
|
+
test do
|
53
|
+
(5.to_roman + 6).assert == 11
|
54
|
+
(2.to_roman + 3.to_roman).assert == 5
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
data/test/string_case.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'roman'
|
2
|
+
|
3
|
+
TestCase String do
|
4
|
+
|
5
|
+
Method :to_roman do
|
6
|
+
test "single digit conversions" do
|
7
|
+
"I".to_roman.assert == RomanNumeral.new(1)
|
8
|
+
"V".to_roman.assert == RomanNumeral.new(5)
|
9
|
+
"X".to_roman.assert == RomanNumeral.new(10)
|
10
|
+
|
11
|
+
"i".to_roman.assert == RomanNumeral.new(1)
|
12
|
+
"v".to_roman.assert == RomanNumeral.new(5)
|
13
|
+
"x".to_roman.assert == RomanNumeral.new(10)
|
14
|
+
end
|
15
|
+
|
16
|
+
test "simple mulit-digit conversions" do
|
17
|
+
"IV".to_roman.assert == RomanNumeral.new(4)
|
18
|
+
"VI".to_roman.assert == RomanNumeral.new(6)
|
19
|
+
"VII".to_roman.assert == RomanNumeral.new(7)
|
20
|
+
"VIII".to_roman.assert == RomanNumeral.new(8)
|
21
|
+
"IX".to_roman.assert == RomanNumeral.new(9)
|
22
|
+
"XI".to_roman.assert == RomanNumeral.new(11)
|
23
|
+
"XII".to_roman.assert == RomanNumeral.new(12)
|
24
|
+
"XIII".to_roman.assert == RomanNumeral.new(13)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "complex conversions" do
|
28
|
+
"XXIV".to_roman.assert == RomanNumeral.new(24)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trans
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: detroit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ergo
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rubytest-cli
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: lemon
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: ae
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: RomanNumeral class for working with roman numerals in a native form.
|
95
|
+
email:
|
96
|
+
- transfire@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- LICENSE.txt
|
101
|
+
- HISTORY.md
|
102
|
+
- README.md
|
103
|
+
files:
|
104
|
+
- .index
|
105
|
+
- lib/roman.rb
|
106
|
+
- lib/roman.yml
|
107
|
+
- test/string_case.rb
|
108
|
+
- test/fixnum_case.rb
|
109
|
+
- test/roman_case.rb
|
110
|
+
- LICENSE.txt
|
111
|
+
- HISTORY.md
|
112
|
+
- README.md
|
113
|
+
homepage: http://rubyworks.github.com/roman
|
114
|
+
licenses:
|
115
|
+
- BSD-2-Clause
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.24
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Real Roman Numerals
|
138
|
+
test_files:
|
139
|
+
- test/string_case.rb
|
140
|
+
- test/fixnum_case.rb
|
141
|
+
- test/roman_case.rb
|
142
|
+
has_rdoc:
|