roman_numeral_evaluator 0.0.2 → 0.0.3
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/lib/roman_numeral_evaluator.rb +0 -2
- data/lib/version.rb +1 -1
- data/readme.md +5 -5
- data/roman_numeral_evaluator.gemspec +1 -1
- metadata +2 -6
- data/lib/string.rb +0 -25
- data/spec/string_spec.rb +0 -29
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative 'version'
|
2
|
-
require_relative 'string'
|
3
2
|
|
4
3
|
module RomanNumeralEvaluator
|
5
4
|
|
@@ -51,7 +50,6 @@ module RomanNumeralEvaluator
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def self.to_decimal(value)
|
54
|
-
value.upcase!
|
55
53
|
result = 0
|
56
54
|
DIGITS.values.reverse.each do |roman|
|
57
55
|
while value.start_with? roman
|
data/lib/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
## About
|
2
2
|
|
3
|
-
A Ruby gem that
|
4
|
-
|
5
|
-
"V" + "V"
|
6
|
-
=> "X"
|
3
|
+
A Ruby gem that solves Roman numeral math problems as strings.
|
7
4
|
|
8
5
|
RomanNumeralEvaluator.solve("I + I")
|
9
6
|
=> "II"
|
@@ -14,7 +11,10 @@ In your gemfile
|
|
14
11
|
|
15
12
|
gem 'roman_numeral_evaluator'
|
16
13
|
|
14
|
+
And execute:
|
17
15
|
|
16
|
+
$ bundle install
|
17
|
+
|
18
18
|
## Usage
|
19
19
|
|
20
20
|
Basic problem
|
@@ -35,7 +35,7 @@ You can multiply!
|
|
35
35
|
RomanNumeralEvaluator.solve('X * X')
|
36
36
|
=> "C"
|
37
37
|
|
38
|
-
Mix Roman and Arabic
|
38
|
+
Mix Roman and Arabic.
|
39
39
|
|
40
40
|
RomanNumeralEvaluator.solve('X * 10')
|
41
41
|
=> "C"
|
@@ -4,7 +4,7 @@ require File.expand_path('../lib/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Travis Sheppard"]
|
6
6
|
gem.email = ["travissheppard.1988@gmail.com"]
|
7
|
-
gem.description = "A Ruby gem that
|
7
|
+
gem.description = "A Ruby gem that solves Roman numeral math problems as strings."
|
8
8
|
gem.summary = ""
|
9
9
|
gem.homepage = ""
|
10
10
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roman_numeral_evaluator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,8 +27,7 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
description: A Ruby gem that
|
31
|
-
as well as handle Roman math problems as strings.
|
30
|
+
description: A Ruby gem that solves Roman numeral math problems as strings.
|
32
31
|
email:
|
33
32
|
- travissheppard.1988@gmail.com
|
34
33
|
executables: []
|
@@ -41,13 +40,11 @@ files:
|
|
41
40
|
- Rakefile
|
42
41
|
- lib/LICENSE
|
43
42
|
- lib/roman_numeral_evaluator.rb
|
44
|
-
- lib/string.rb
|
45
43
|
- lib/version.rb
|
46
44
|
- readme.md
|
47
45
|
- roman_numeral_evaluator.gemspec
|
48
46
|
- spec/roman_numeral_evaluator_spec.rb
|
49
47
|
- spec/spec_helper.rb
|
50
|
-
- spec/string_spec.rb
|
51
48
|
homepage: ''
|
52
49
|
licenses: []
|
53
50
|
post_install_message:
|
@@ -75,4 +72,3 @@ summary: ''
|
|
75
72
|
test_files:
|
76
73
|
- spec/roman_numeral_evaluator_spec.rb
|
77
74
|
- spec/spec_helper.rb
|
78
|
-
- spec/string_spec.rb
|
data/lib/string.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
def +(a)
|
4
|
-
if RomanNumeralEvaluator.is_roman?(self) || RomanNumeralEvaluator.is_roman?(a)
|
5
|
-
number = RomanNumeralEvaluator.to_decimal(self)
|
6
|
-
other = RomanNumeralEvaluator.to_decimal(a)
|
7
|
-
RomanNumeralEvaluator.to_roman(number + other)
|
8
|
-
else
|
9
|
-
self << a
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def -(a)
|
14
|
-
RomanNumeralEvaluator.solve("#{self} - #{a}")
|
15
|
-
end
|
16
|
-
|
17
|
-
def *(a)
|
18
|
-
RomanNumeralEvaluator.solve("#{self} * #{a}")
|
19
|
-
end
|
20
|
-
|
21
|
-
def /(a)
|
22
|
-
RomanNumeralEvaluator.solve("#{self} / #{a}")
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/spec/string_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
|
5
|
-
it "should add roman numerals" do
|
6
|
-
result = "V" + "V"
|
7
|
-
result.should eq("X")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should subtract roman numerals" do
|
11
|
-
result = "II" - "I"
|
12
|
-
result.should eq("I")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should multiply roman numerals" do
|
16
|
-
result = "II" * "II"
|
17
|
-
result.should eq("IV")
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should divide roman numerals" do
|
21
|
-
result = "C" / "X"
|
22
|
-
result.should eq("X")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should add non roman strings normally" do
|
26
|
-
("a" + "b").should eq("ab")
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|