romanumerals 0.1.1 → 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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -2
- data/lib/romanumerals/numeric.rb +1 -1
- data/lib/romanumerals/string.rb +56 -0
- data/lib/romanumerals/version.rb +1 -1
- data/lib/romanumerals.rb +1 -0
- data/sig/romanumerals/string.rbs +13 -0
- data/sig/romanumerals.rbs +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89ee3edbf76f972387873e7c65abb886ffacfc0c20f4c5cd761dcbfbea6cd4c0
|
4
|
+
data.tar.gz: b92715147ea27d486218dba49c450b4dc7697f1c2c38c87f9451a6aa44133401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edeb84a0cc156f64f236b13b91e7fac471c6b5064f0be2a715fadb941aa38138bbf2599ccb6239fa40fcc1ec7d371989806f6abcec2f3651a19f5560feab0c5a
|
7
|
+
data.tar.gz: 762a9db1bff5156091188d631fff66123f3ce411b6bc8077c4e5e1f49095d4b06722d23d08e739d927f648ce16f0f70169caf449f8ab7740494115835c07f553
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
romanumerals (0.1.
|
4
|
+
romanumerals (0.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -53,6 +53,7 @@ GEM
|
|
53
53
|
|
54
54
|
PLATFORMS
|
55
55
|
x86_64-darwin-20
|
56
|
+
x86_64-darwin-21
|
56
57
|
x86_64-linux
|
57
58
|
|
58
59
|
DEPENDENCIES
|
@@ -63,4 +64,4 @@ DEPENDENCIES
|
|
63
64
|
rubocop (~> 1.21)
|
64
65
|
|
65
66
|
BUNDLED WITH
|
66
|
-
2.3.
|
67
|
+
2.3.14
|
data/lib/romanumerals/numeric.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Romanumerals
|
4
|
+
DICTIONARY_SORTED_BY_WEIGHT = {
|
5
|
+
'CM' => 900,
|
6
|
+
'CD' => 400,
|
7
|
+
'XC' => 90,
|
8
|
+
'XL' => 40,
|
9
|
+
'IX' => 9,
|
10
|
+
'IV' => 4,
|
11
|
+
'M' => 1000,
|
12
|
+
'D' => 500,
|
13
|
+
'C' => 100,
|
14
|
+
'L' => 50,
|
15
|
+
'X' => 10,
|
16
|
+
'V' => 5,
|
17
|
+
'I' => 1
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
module String
|
21
|
+
def to_numeral
|
22
|
+
return to_i unless roman?
|
23
|
+
|
24
|
+
decompose.map { |value, count| DICTIONARY_SORTED_BY_WEIGHT[value] * count }.sum
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_roman
|
28
|
+
to_i.to_roman
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def roman?
|
34
|
+
match?(/^[IVXMCDL]*$/)
|
35
|
+
end
|
36
|
+
|
37
|
+
def decompose
|
38
|
+
initial_string = dup
|
39
|
+
|
40
|
+
DICTIONARY_SORTED_BY_WEIGHT.keys.each_with_object({}) do |value, result|
|
41
|
+
matches_count = initial_string.scan(/#{value}/).size
|
42
|
+
result[value] ||= 0
|
43
|
+
|
44
|
+
matches_count.times do
|
45
|
+
initial_string.sub!(/#{value}/, '')
|
46
|
+
|
47
|
+
result[value] += 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class String
|
55
|
+
include Romanumerals::String
|
56
|
+
end
|
data/lib/romanumerals/version.rb
CHANGED
data/lib/romanumerals.rb
CHANGED
data/sig/romanumerals.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: romanumerals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- febonazzic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".rspec"
|
21
21
|
- ".rubocop.yml"
|
22
|
+
- ".ruby-version"
|
22
23
|
- CHANGELOG.md
|
23
24
|
- Gemfile
|
24
25
|
- Gemfile.lock
|
@@ -27,9 +28,11 @@ files:
|
|
27
28
|
- Rakefile
|
28
29
|
- lib/romanumerals.rb
|
29
30
|
- lib/romanumerals/numeric.rb
|
31
|
+
- lib/romanumerals/string.rb
|
30
32
|
- lib/romanumerals/version.rb
|
31
33
|
- sig/romanumerals.rbs
|
32
34
|
- sig/romanumerals/numeric.rbs
|
35
|
+
- sig/romanumerals/string.rbs
|
33
36
|
homepage: https://github.com/febonazzic/romanumerals
|
34
37
|
licenses:
|
35
38
|
- MIT
|