galaxy_converter 3.1.2 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7f0865539e739036e79313e9d9b65227d3b0cc1d22e5156332a39f642098500
4
- data.tar.gz: 5d9f6de7ef78706cf1380b5c199e97b3703c17d4ffea755e8669d2420911213a
3
+ metadata.gz: c48f08e77a74b98ab61cfb545116a8ab1fe1e02855f1861f842d44182f96e76e
4
+ data.tar.gz: '059236058f8486ed9a3442ce525ff8d700fa51e80014b85ad3f30014fcd8eb51'
5
5
  SHA512:
6
- metadata.gz: 6cb4fb0d5580bdc0642dda78eb2b2ba58300272474eb4e94ab2a9a4e1b0d88aeb95ee1362d33fce1d1400781b1da3bd52913985eac93b9ff8aa70d9c2ec068c1
7
- data.tar.gz: d1be7f1f07456e668694cc4dd8e29e73c1f1f0fa9223340766eb53650c412a22e6ab21543ffa771745d0f0fd686355f5a7f25663808807e3a81881e3451e9ae9
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
- * [CLI](#cli)
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
- ### CLI
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 ||= repetitions + subtractions
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
- notes = notes.reject(&:question?)
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
- @mapping ||= @assertions.reduce({}) do |acc, note|
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 unless valid?
35
- stretched.chars.sum { |symbol| SYMBOLS.fetch(symbol, 0) }
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 stretched
39
- @stretched ||= STRETCH_MAP.reduce(@value) do |value, (long, short)|
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
@@ -1,3 +1,3 @@
1
1
  module GalaxyConverter
2
- VERSION = "3.1.2"
2
+ VERSION = "3.1.3"
3
3
  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.2
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-02 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler