galaxy_converter 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/galaxy_converter/constraint.rb +1 -10
- data/lib/galaxy_converter/detector.rb +2 -3
- data/lib/galaxy_converter/roman_numeral.rb +4 -12
- data/lib/galaxy_converter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c48f08e77a74b98ab61cfb545116a8ab1fe1e02855f1861f842d44182f96e76e
|
4
|
+
data.tar.gz: '059236058f8486ed9a3442ce525ff8d700fa51e80014b85ad3f30014fcd8eb51'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a324e325d47d5ede327c036a59f8f3487084b2c080ff22fc6599731f0e089cf7e6ad856f02bd8aa3307562d19e1d07833ae88d5c10f59f40128c2301e64c324
|
7
|
+
data.tar.gz: 6037b4ca02e5b73ffef27601bf464d9c2e0c8824b35f34b72655f6e2e7f886fcaddcfcd462a996daa0d0b6c0a3d08be0aa9bad95d8287baf62f99d8c3fe93fe4
|
data/README.md
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
* [Roman numerals](#roman-numerals)
|
6
6
|
* [Installation](#installation)
|
7
7
|
* [Usage](#usage)
|
8
|
-
* [
|
8
|
+
* [Input](#input)
|
9
|
+
* [Output](#output)
|
9
10
|
|
10
11
|
## Scope
|
11
12
|
This gem is the Ruby implementation of the `Merchant's Guide to the Galaxy` code-kata.
|
@@ -27,9 +28,8 @@ gem install galaxy_converter
|
|
27
28
|
|
28
29
|
## Usage
|
29
30
|
|
30
|
-
###
|
31
|
-
The gem provides a CLI interface
|
32
|
-
The program accepts as input a file containing several conversion notes:
|
31
|
+
### Input
|
32
|
+
The gem provides a CLI interface accepting as input a file containing several conversion notes:
|
33
33
|
```txt
|
34
34
|
# ~/notes.txt
|
35
35
|
glob is I
|
@@ -46,6 +46,7 @@ how many Credits is glob prok Iron ?
|
|
46
46
|
how much wood could a woodchuck chuck if a woodchuck could chuck wood ?
|
47
47
|
```
|
48
48
|
|
49
|
+
### Output
|
49
50
|
Just pass the file path to the program:
|
50
51
|
```shell
|
51
52
|
galaxy_converter ~/notes.txt
|
@@ -3,16 +3,11 @@ module GalaxyConverter
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def call(value)
|
6
|
-
return if value.empty?
|
7
6
|
violations.any? { |violation| value.index(violation) }
|
8
7
|
end
|
9
8
|
|
10
9
|
private def violations
|
11
|
-
@violations ||=
|
12
|
-
end
|
13
|
-
|
14
|
-
private def repetitions
|
15
|
-
too_many_repetitions + unrepeatable
|
10
|
+
@violations ||= too_many_repetitions + unrepeatable + repeated_sub + wrong_sub
|
16
11
|
end
|
17
12
|
|
18
13
|
private def too_many_repetitions
|
@@ -23,10 +18,6 @@ module GalaxyConverter
|
|
23
18
|
%w[D L V].map { |c| c * 2 }
|
24
19
|
end
|
25
20
|
|
26
|
-
private def subtractions
|
27
|
-
repeated_sub + wrong_sub
|
28
|
-
end
|
29
|
-
|
30
21
|
private def repeated_sub
|
31
22
|
%w[V X].map { |c| "II#{c}"} +
|
32
23
|
%w[L C].map { |c| "XX#{c}"} +
|
@@ -9,8 +9,7 @@ module GalaxyConverter
|
|
9
9
|
attr_reader :converter
|
10
10
|
|
11
11
|
def initialize(notes, converter = Converter)
|
12
|
-
|
13
|
-
@credits, @assertions = notes.partition { |note| note.instance_of? Credit }
|
12
|
+
@credits, @assertions = notes.reject(&:question?).partition { |note| note.instance_of? Credit }
|
14
13
|
@converter = converter.new(mapping)
|
15
14
|
end
|
16
15
|
|
@@ -27,7 +26,7 @@ module GalaxyConverter
|
|
27
26
|
end
|
28
27
|
|
29
28
|
private def mapping
|
30
|
-
@
|
29
|
+
@assertions.reduce({}) do |acc, note|
|
31
30
|
matching = note.body.match(MAPPING_RULE)
|
32
31
|
next acc unless matching
|
33
32
|
unit, roman = matching.captures
|
@@ -26,23 +26,15 @@ module GalaxyConverter
|
|
26
26
|
@constraint = constraint
|
27
27
|
end
|
28
28
|
|
29
|
-
def to_s
|
30
|
-
@value
|
31
|
-
end
|
32
|
-
|
33
29
|
def to_i
|
34
|
-
return 0
|
35
|
-
|
30
|
+
return 0 if @constraint.call(@value)
|
31
|
+
to_l.chars.sum { |symbol| SYMBOLS.fetch(symbol, 0) }
|
36
32
|
end
|
37
33
|
|
38
|
-
private def
|
39
|
-
|
34
|
+
private def to_l
|
35
|
+
STRETCH_MAP.reduce(@value) do |value, (long, short)|
|
40
36
|
value.gsub(short, long)
|
41
37
|
end
|
42
38
|
end
|
43
|
-
|
44
|
-
private def valid?
|
45
|
-
!@constraint.call(@value)
|
46
|
-
end
|
47
39
|
end
|
48
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galaxy_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- costajob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|