roman_numerals 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/Rakefile +7 -0
- data/lib/roman_numerals.rb +40 -0
- data/lib/roman_numerals/version.rb +3 -0
- data/roman_numerals.gemspec +22 -0
- data/spec/roman_numerals_spec.rb +96 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c699ac562d648abec9680c660e68efedbd82b38c
|
4
|
+
data.tar.gz: 4da2d24cc705819cabc09e8e2cecac32c9095536
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 625a05f67b672bbd3dcb66f874f2932f830bc6e6acbd0a2c9a3d273b51cc5ab63c730347a75c788b186f041ece0af42502a191a999d7903aa000c90670a25d36
|
7
|
+
data.tar.gz: 548d4f5cf014268c41cc078dbba390f7545e815e0fe9a0ecaf865ab532bae5b53e773a77146478a1d22da0d5d913acb66fa024dd5d382eb701ef5aa7d7238971
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module RomanNumerals
|
2
|
+
|
3
|
+
def r_to_i()
|
4
|
+
|
5
|
+
numeral = self
|
6
|
+
value = 0
|
7
|
+
|
8
|
+
if numeral.empty?
|
9
|
+
return nil
|
10
|
+
end
|
11
|
+
|
12
|
+
numeral.strip!
|
13
|
+
numeral.upcase!
|
14
|
+
|
15
|
+
if (numeral != numeral[/[MCDLXVI]*/])
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
|
19
|
+
until numeral.length == 0 do
|
20
|
+
value += 900 unless (numeral.sub! "CM", "").nil?
|
21
|
+
value += 1000 unless (numeral.sub! "M", "").nil?
|
22
|
+
value += 400 unless (numeral.sub! "CD", "").nil?
|
23
|
+
value += 500 unless (numeral.sub! "D", "").nil?
|
24
|
+
value += 90 unless (numeral.sub! "XC", "").nil?
|
25
|
+
value += 100 unless (numeral.sub! "C", "").nil?
|
26
|
+
value += 40 unless (numeral.sub! "XL", "").nil?
|
27
|
+
value += 50 unless (numeral.sub! "L", "").nil?
|
28
|
+
value += 9 unless (numeral.sub! "IX", "").nil?
|
29
|
+
value += 10 unless (numeral.sub! "X", "").nil?
|
30
|
+
value += 4 unless (numeral.sub! "IV", "").nil?
|
31
|
+
value += 5 unless (numeral.sub! "V", "").nil?
|
32
|
+
value += 1 unless (numeral.sub! "I", "").nil?
|
33
|
+
end
|
34
|
+
value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class String
|
39
|
+
include RomanNumerals
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'roman_numerals/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "roman_numerals"
|
7
|
+
gem.version = RomanNumerals::VERSION
|
8
|
+
gem.authors = ["abwinkler999"]
|
9
|
+
gem.email = ["abwinkler999@gmail.com"]
|
10
|
+
gem.description = %q{Converts Roman numerals into integers}
|
11
|
+
gem.summary = %q{Adds .r_to_i method to String, to convert a Roman numeral string to integer}
|
12
|
+
gem.homepage = "http://www.github.com/abwinkler999/roman_numeral_gem"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.license = 'MIT'
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'roman_numerals'
|
2
|
+
|
3
|
+
describe RomanNumerals do
|
4
|
+
|
5
|
+
it "refuses to parse strings that are not Roman numerals" do
|
6
|
+
"".r_to_i.should == nil
|
7
|
+
"FOO".r_to_i.should == nil
|
8
|
+
"XXVIIQ".r_to_i.should == nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can parse I into 1" do
|
12
|
+
"I".r_to_i.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can clean up poorly formatted arguments" do
|
16
|
+
"i".r_to_i.should == 1
|
17
|
+
" i ".r_to_i.should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can parse II into 2" do
|
21
|
+
"II".r_to_i.should == 2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can parse III into 3" do
|
25
|
+
"III".r_to_i.should == 3
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can parse IV into 4" do
|
29
|
+
"IV".r_to_i.should == 4
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can parse V into 5" do
|
33
|
+
"V".r_to_i.should == 5
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can parse VI into 6" do
|
37
|
+
"VI".r_to_i.should == 6
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can parse VII into 7" do
|
41
|
+
"VII".r_to_i.should == 7
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can parse VI into 8" do
|
45
|
+
"VIII".r_to_i.should == 8
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can parse X into 10" do
|
49
|
+
"X".r_to_i.should == 10
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can parse IX into 9" do
|
53
|
+
"IX".r_to_i.should == 9
|
54
|
+
end
|
55
|
+
|
56
|
+
it "can parse XIII into 13" do
|
57
|
+
"XIII".r_to_i.should == 13
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can parse L into 50" do
|
61
|
+
"L".r_to_i.should == 50
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can parse LII into 52" do
|
65
|
+
"LII".r_to_i.should == 52
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can parse XIV into 14" do
|
69
|
+
"XIV".r_to_i.should == 14
|
70
|
+
end
|
71
|
+
|
72
|
+
it "can parse DCLXVI into 666" do
|
73
|
+
"DCLXVI".r_to_i.should == 666
|
74
|
+
end
|
75
|
+
|
76
|
+
it "can parse MCMLXXXVIII into 1988" do
|
77
|
+
"MCMLXXXVIII".r_to_i.should == 1988
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can parse XL into 40" do
|
81
|
+
"XL".r_to_i.should == 40
|
82
|
+
end
|
83
|
+
|
84
|
+
it "can parse XC into 90" do
|
85
|
+
"XC".r_to_i.should == 90
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can parse CD into 400" do
|
89
|
+
"CD".r_to_i.should == 400
|
90
|
+
end
|
91
|
+
|
92
|
+
it "can parse CM into 900" do
|
93
|
+
"CM".r_to_i.should == 900
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roman_numerals
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- abwinkler999
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Converts Roman numerals into integers
|
42
|
+
email:
|
43
|
+
- abwinkler999@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- Gemfile
|
51
|
+
- Rakefile
|
52
|
+
- lib/roman_numerals.rb
|
53
|
+
- lib/roman_numerals/version.rb
|
54
|
+
- roman_numerals.gemspec
|
55
|
+
- spec/roman_numerals_spec.rb
|
56
|
+
homepage: http://www.github.com/abwinkler999/roman_numeral_gem
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.1.11
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Adds .r_to_i method to String, to convert a Roman numeral string to integer
|
80
|
+
test_files:
|
81
|
+
- spec/roman_numerals_spec.rb
|