numeri_romani 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb3e4badf6825238229abe82da019fc74bcbf8ee
4
- data.tar.gz: 0a4e95fc56fa671206e3ac3977093f78b380522a
3
+ metadata.gz: 8ade03b2c587a395bdca23e658076da1888882da
4
+ data.tar.gz: 87e101a9b9f99d9f110d9a54a70fd56f2f459269
5
5
  SHA512:
6
- metadata.gz: 04e541f461c1f5853eaa08bc272a6e965b12addb8f03f7f9c7facaf59acc05f0656ce7fb251a003d4e1810aeafbf58a0ceb38cb9c11dffbfa1177f6d49ec1621
7
- data.tar.gz: 5317c33f4128e1fe2d6fccd2f14f1e3b24433098f89b151d90a5173ddf71aba3075236734bb18558f83a3785e7f1309f90c9494f1ca276c403f401e25c59436c
6
+ metadata.gz: 5bb59e7553ce3b684ff4f5ef5b8876e724febb9a5bcb434897e157dffdcbce790896f7eee5183fd34837f5f27e65296e68e911c7ec8f184edbc7a5aee9403389
7
+ data.tar.gz: 2abf0cf00f9dc25b30e34bb7b6a8de284ab07dc3ac80e072d2e5584c81f17ab8af01c1d853abf57240a0aa89b34c13056849db66725429977bb9c8cfdeb993ed
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # NumeriRomani
2
2
 
3
- Simple library for conversion integers to roman numerals and roman numerals to integers.
3
+ Numeri Romani (lat. roman numerals) - simple library for conversion integers to roman numerals and roman numerals to integers.
4
+ Convert numbers within range of 1..3_999_999.
4
5
 
5
6
  ## Installation
6
7
 
@@ -38,6 +39,16 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
38
39
  4) Push to the branch (git push origin my-new-feature)
39
40
  5) Create a new Pull Request
40
41
 
42
+ Contributions are welcome!
43
+
44
+ Here's some ideas (maybe also a roadmap for possible future versions of the library):
45
+
46
+ * **Add Apostrophus system for big numbers.** For instance: CCC|ƆƆƆ|ƆƆƆ (C̅X̅X̅MMMCXXIII)
47
+
48
+ * **Extend for fractions**. For instance S: - 2/3, S:·: - 11/12
49
+
50
+ * **Add Validation module**.
51
+
41
52
  ## License
42
53
 
43
54
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,5 +1,17 @@
1
1
  module NumeriRomani
2
2
  DIGITS = {
3
+ 'M̅' => 1_000_000,
4
+ 'C̅M̅' => 900_000,
5
+ 'D̅' => 500_000,
6
+ 'C̅D̅' => 400_000,
7
+ 'C̅' => 100_000,
8
+ 'X̅C̅' => 90_000,
9
+ 'L̅' => 50_000,
10
+ 'X̅L̅' => 40_000,
11
+ 'X̅' => 10_000,
12
+ 'I̅X̅' => 9_000,
13
+ 'V̅' => 5_000,
14
+ 'I̅V̅' => 4_000,
3
15
  'M' => 1_000,
4
16
  'CM' => 900,
5
17
  'D' => 500,
@@ -14,4 +26,6 @@ module NumeriRomani
14
26
  'IV' => 4,
15
27
  'I' => 1
16
28
  }.freeze
29
+
30
+ REGEXP = /^((M\u0305){0,3})((D\u0305)?(C\u0305){0,3}|C\u0305D\u0305|C\u0305M\u0305)((L\u0305)?(X\u0305){0,3}|X\u0305L\u0305|X\u0305C\u0305)((V\u0305)?(I\u0305){0,3}|I\u0305V\u0305|I\u0305X\u0305)(M{0,3})(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/
17
31
  end
@@ -1,3 +1,3 @@
1
1
  module NumeriRomani
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/numeri_romani.rb CHANGED
@@ -4,7 +4,8 @@ require 'numeri_romani/digits'
4
4
  module NumeriRomani
5
5
  class << self
6
6
  def to_roman(decimal_number)
7
- raise ArgumentError unless decimal_number.between?(1, 3_999)
7
+ raise ArgumentError.new('Number should be an Integer') unless decimal_number.is_a?(Integer)
8
+ raise ArgumentError.new('Number should be in interval [1..3_999_999]') unless decimal_number.between?(1, 3_999_999)
8
9
  DIGITS.map do |letter, value|
9
10
  count, decimal_number = decimal_number.divmod(value)
10
11
  [letter * count]
@@ -12,7 +13,7 @@ module NumeriRomani
12
13
  end
13
14
 
14
15
  def to_decimal(roman_number)
15
- raise ArgumentError unless roman_number.match?(/^(M{0,3})(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/)
16
+ raise ArgumentError.new('Not valid roman number') unless roman_number.match?(REGEXP)
16
17
  roman_number.scan(/#{DIGITS.keys.join('|')}/).sum { |let| DIGITS[let] }
17
18
  end
18
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numeri_romani
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Petrov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-06 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler