romanumerals 0.2.0 → 0.2.1
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/Gemfile.lock +1 -1
- data/README.md +18 -0
- data/lib/romanumerals/numeric.rb +1 -6
- data/lib/romanumerals/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce9a2c835b1abd6e4aede7c8aad10ca02abb19532da0c6389e6207deffacf96f
|
4
|
+
data.tar.gz: 8ca0e19c63694bb28ee450d88e64e9578d2a97a88a4f71b275bf35df45c93fcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb90ef45faf6f20cfd82c9cbc5f73139dd161f9bac6be11f85b30a41463a54c547dae130f3ae716e2bc9083ec9b4195f9ab34bcfbed9a3868dede773a70bb4a
|
7
|
+
data.tar.gz: b292909557427f0ab63deca96206de50cea434b63dc106590be8711e18c3d2fce03608013affe0b5d8d4e6611fa3c9f3b7e0c45c3107f23a7c2ecd85b589f7e9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
18
|
|
19
19
|
Usage is very simple:
|
20
20
|
|
21
|
+
#### Convert to roman:
|
21
22
|
```ruby
|
22
23
|
10.to_roman # => "X"
|
23
24
|
110.to_roman # => "CX"
|
@@ -27,6 +28,23 @@ Usage is very simple:
|
|
27
28
|
2022.to_roman # => "MMXXII"
|
28
29
|
```
|
29
30
|
|
31
|
+
#### Convert from roman:
|
32
|
+
```ruby
|
33
|
+
'MMXXII'.to_numeral # => 2022
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Other cases:
|
37
|
+
```ruby
|
38
|
+
0.to_roman # => ""
|
39
|
+
11.9.to_roman # => "XI"
|
40
|
+
|
41
|
+
# If a string does not contain roman numerals then the String#to_i will be used
|
42
|
+
''.to_numeral # => 0
|
43
|
+
'0'.to_numeral # => 0
|
44
|
+
'XIIi'.to_numeral # => 0
|
45
|
+
'5 contributors'.to_numeral # => 5
|
46
|
+
```
|
47
|
+
|
30
48
|
## Contributing
|
31
49
|
|
32
50
|
Bug reports and pull requests are welcome on GitHub at https://github.com/febonazzic/romanumerals.
|
data/lib/romanumerals/numeric.rb
CHANGED
@@ -6,12 +6,7 @@ module Romanumerals
|
|
6
6
|
return '' if zero?
|
7
7
|
|
8
8
|
decompose.each_with_object([]) do |(divider, count), result|
|
9
|
-
result <<
|
10
|
-
if count == 4
|
11
|
-
DICTIONARY[divider] + DICTIONARY[divider * 5]
|
12
|
-
else
|
13
|
-
DICTIONARY[divider] * count
|
14
|
-
end
|
9
|
+
result << DICTIONARY[divider] * count
|
15
10
|
end.join
|
16
11
|
end
|
17
12
|
|
data/lib/romanumerals/version.rb
CHANGED