codebreaker_mats 0.1.3 → 0.1.8

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: 16bce1a1da5e00621cc1021bc0ffd03f8d6be75598442e7d6e74e195973d748b
4
- data.tar.gz: 1a2b05e7c0ab2290f737676d03e85a2e3c69a1dcb1bfaa16a5bed61184e125e9
3
+ metadata.gz: 83d5e29074b2fdaf5e7c044c172ffd9755b4ddff1a3de701d333937dfb9e16ef
4
+ data.tar.gz: e312feec5e50c2eb42129683844c3e6cee8fc3680c8e4d2c69356a520aba20be
5
5
  SHA512:
6
- metadata.gz: 4b9e33e9018bf5f0ab7ddd01cc2a05fce049d2f6e71c0f67cf20ebfb4e5744e6b3b0c853cddc65888c464b3582b85bd1b44cfbe64d8041291d03089635397735
7
- data.tar.gz: 209b63bddb171887211829ce81b4cfd2fce9b01c31a4632b7192265658ed3c9804f52ea1508fbe25110b79d8ff531e5a4befc49b64e9e4abb20f1e4c15576246
6
+ metadata.gz: ac0ad2437664cf99f9aea24ce5a4b3d7d158a5bf4f591efa2db75427285c04c8e0ddb0a46ddfea717f870e9bf477442b51108b4edd4da6ae4d5de521ed8ab692
7
+ data.tar.gz: 04cec421ad7a2531b2d3f981c04fef03024e7bd541f5fdd3ffbdcad9accecb9df62df0dd9a01aa3551da42de3dc8b8e9b0ee1ad47a40a3f4f5792416c28a0f54
@@ -0,0 +1,70 @@
1
+ version: 2.1
2
+
3
+ executors:
4
+ default:
5
+ working_directory: ~/repo
6
+ description: The official CircleCI Ruby Docker image
7
+ docker:
8
+ - image: circleci/ruby:2.6.0-node
9
+ environment:
10
+ BUNDLER_VERSION: 2.1.4
11
+
12
+ caches:
13
+ - &bundle_cache_full v2-repo-{{ checksum "Gemfile.lock" }}
14
+ - &bundle_cache v2-repo-
15
+
16
+ commands:
17
+ defaults:
18
+ steps:
19
+ - checkout
20
+ - restore_cache:
21
+ keys:
22
+ - *bundle_cache_full
23
+ - *bundle_cache
24
+ - run:
25
+ name: Configure Bundler
26
+ command: |
27
+ gem update --system
28
+ gem install bundler
29
+ - run: bundle install --path vendor/bundle
30
+ - save_cache:
31
+ key: *bundle_cache_full
32
+ paths:
33
+ - vendor/bundle
34
+ run_linters:
35
+ description: command to start linters
36
+ steps:
37
+ - run:
38
+ name: rubocop
39
+ command: bundle exec rubocop
40
+
41
+ run_specs:
42
+ steps:
43
+ - run:
44
+ name: run specs
45
+ command: |
46
+ mkdir /tmp/test-results
47
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
48
+ bundle exec rspec --format progress \
49
+ --out /tmp/test-results/rspec.xml \
50
+ $TEST_FILES
51
+ jobs:
52
+ lintering:
53
+ executor: default
54
+ steps:
55
+ - defaults
56
+ - run_linters
57
+ run_specs:
58
+ executor: default
59
+ steps:
60
+ - defaults
61
+ - run_specs
62
+
63
+ workflows:
64
+ version: 2
65
+ build:
66
+ jobs:
67
+ - lintering
68
+ - run_specs:
69
+ requires:
70
+ - lintering
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/
1
+ j/.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
@@ -0,0 +1,14 @@
1
+ require: rubocop-rspec
2
+ Style:
3
+ Enabled: false
4
+ RSpec/FilePath:
5
+ Enabled: false
6
+ RSpec/MultipleExpectations:
7
+ Enabled: false
8
+ RSpec/MessageSpies:
9
+ Enabled: false
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'Rakefile'
13
+ - '**/*.rake'
14
+ - 'spec/**/*.rb'
@@ -0,0 +1 @@
1
+ ruby 2.7.1
@@ -0,0 +1,3 @@
1
+ {
2
+ "liveServer.settings.port": 5501
3
+ }
data/Gemfile CHANGED
@@ -1,8 +1,11 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in codebreaker_mats.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
- gem 'simplecov'
6
+ gem 'fasterer', '0.8.3'
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rubocop-rspec', require: false
10
+
11
+ gem 'simplecov'
@@ -1,14 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_mats (0.1.3)
4
+ codebreaker_mats (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.1)
10
+ colorize (0.8.1)
9
11
  diff-lcs (1.4.4)
10
12
  docile (1.3.2)
13
+ fasterer (0.8.3)
14
+ colorize (~> 0.7)
15
+ ruby_parser (>= 3.14.1)
16
+ parallel (1.19.2)
17
+ parser (2.7.1.4)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
11
20
  rake (12.3.3)
21
+ regexp_parser (1.7.1)
22
+ rexml (3.2.4)
12
23
  rspec (3.9.0)
13
24
  rspec-core (~> 3.9.0)
14
25
  rspec-expectations (~> 3.9.0)
@@ -22,18 +33,38 @@ GEM
22
33
  diff-lcs (>= 1.2.0, < 2.0)
23
34
  rspec-support (~> 3.9.0)
24
35
  rspec-support (3.9.3)
36
+ rubocop (0.88.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.7.1.1)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.7)
41
+ rexml
42
+ rubocop-ast (>= 0.1.0, < 1.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 2.0)
45
+ rubocop-ast (0.2.0)
46
+ parser (>= 2.7.0.1)
47
+ rubocop-rspec (1.42.0)
48
+ rubocop (>= 0.87.0)
49
+ ruby-progressbar (1.10.1)
50
+ ruby_parser (3.14.2)
51
+ sexp_processor (~> 4.9)
52
+ sexp_processor (4.14.1)
25
53
  simplecov (0.18.5)
26
54
  docile (~> 1.1)
27
55
  simplecov-html (~> 0.11)
28
56
  simplecov-html (0.12.2)
57
+ unicode-display_width (1.7.0)
29
58
 
30
59
  PLATFORMS
31
60
  ruby
32
61
 
33
62
  DEPENDENCIES
34
63
  codebreaker_mats!
64
+ fasterer (= 0.8.3)
35
65
  rake (~> 12.0)
36
66
  rspec (~> 3.0)
67
+ rubocop-rspec
37
68
  simplecov
38
69
 
39
70
  BUNDLED WITH
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "codebreaker_mats"
3
+ require 'bundler/setup'
4
+ require 'codebreaker_mats'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "codebreaker_mats"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,26 +1,26 @@
1
1
  require_relative 'lib/codebreaker_mats/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "codebreaker_mats"
4
+ spec.name = 'codebreaker_mats'
5
5
  spec.version = CodebreakerMats::VERSION
6
- spec.authors = ["Ivan"]
7
- spec.email = ["ivan.matsiyk18092002@gmail.com"]
6
+ spec.authors = ['Ivan']
7
+ spec.email = ['ivan.matsiyk18092002@gmail.com']
8
8
 
9
9
  spec.summary = 'codebreaker game'
10
10
  spec.description = 'The app provides core for codebreaker game'
11
11
  spec.homepage = 'https://github.com/Swooty18/codebreaker_mats.git'
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
14
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = 'https://github.com/Swooty18/codebreaker_mats.git'
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/Swooty18/codebreaker_mats.git'
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
22
  end
23
- spec.bindir = "exe"
23
+ spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
26
26
  end
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
+ require_relative 'codebreaker_mats/stats'
3
4
  require_relative 'codebreaker_mats/version'
4
5
  require_relative 'codebreaker_mats/matcher'
5
6
  require_relative 'codebreaker_mats/game'
@@ -7,7 +8,3 @@ require_relative 'codebreaker_mats/game'
7
8
  require_relative 'codebreaker_mats/exceptions/terminate_error'
8
9
 
9
10
  require_relative 'codebreaker_mats/markers/plus_minus_marker'
10
- require_relative 'codebreaker_mats/markers/classical_marker'
11
-
12
- require 'simplecov'
13
- SimpleCov.start
@@ -1,13 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Codebreaker
4
- # Game of bulls and cows.
5
2
  class Game
6
- attr_reader :storage, :matcher, :hints, :status
3
+ include Stats
4
+ CODE_RANGE_MIN = 1
5
+ CODE_RANGE_MAX = 6
6
+ COUNT_OF_NUMBER = 4
7
+ attr_reader :matcher, :hints, :status
7
8
 
8
9
  attr_accessor :user, :number_of_attempts, :number_of_hints, :attempts_left, :hints_left, :difficulty, :secret_code
9
10
  def initialize(matcher: Matcher.new)
10
- @storage = storage
11
11
  @matcher = matcher
12
12
  end
13
13
 
@@ -51,29 +51,33 @@ module Codebreaker
51
51
  status == :lost
52
52
  end
53
53
 
54
- def in_progress?
55
- status == :in_progress
54
+ def save_stat(stat_file)
55
+ save_stat_in_file(stat_file, stats_hash)
56
56
  end
57
57
 
58
- def save_stat(stat_file)
59
- File.open(stat_file, 'a+') do |f|
60
- f.write({ user: @user,
61
- difficulty: @difficulty,
62
- attempts: @number_of_attempts,
63
- attempts_used: @number_of_attempts - @attempts_left,
64
- hints: @number_of_hints,
65
- hints_used: @number_of_hints - @hints_left }.to_yaml)
66
- end
58
+ def stats_hash
59
+ { user: @user,
60
+ difficulty: @difficulty,
61
+ attempts: @number_of_attempts,
62
+ attempts_used: @number_of_attempts - @attempts_left,
63
+ hints: @number_of_hints,
64
+ hints_used: @number_of_hints - @hints_left }
65
+ end
66
+
67
+ def set_difficulty(diff, attempts, hints)
68
+ @number_of_attempts = @attempts_left = attempts
69
+ @number_of_hints = @hints_left = hints
70
+ @difficulty = diff
67
71
  end
68
72
 
69
73
  private
70
74
 
71
75
  def generate_secret_code
72
- @secret_code = Array.new(4) { roll_dice }.join
76
+ @secret_code = Array.new(COUNT_OF_NUMBER) { roll_dice }.join
73
77
  end
74
78
 
75
79
  def roll_dice
76
- rand(1..6)
80
+ rand(CODE_RANGE_MIN..CODE_RANGE_MAX)
77
81
  end
78
82
 
79
83
  def generate_hints
@@ -2,11 +2,9 @@
2
2
 
3
3
  module Codebreaker
4
4
  module Markers
5
- # Marker that will interpret the number of bulls
6
- # and cows in a codebreaker plus-minus style.
7
5
  class PlusMinusMarker
8
- def mark(bulls, cows)
9
- '+' * bulls + '-' * cows
6
+ def mark(exact, non_exact)
7
+ '+' * exact + '-' * non_exact
10
8
  end
11
9
  end
12
10
  end
@@ -5,10 +5,8 @@ module Codebreaker
5
5
  # of bulls and cows in the guess.
6
6
  class Matcher
7
7
  attr_reader :marker, :secret_code_hash
8
- attr_reader :exact_matches, :all_matches, :bulls, :cows
9
8
  def initialize(marker = Markers::PlusMinusMarker.new)
10
9
  @marker = marker
11
- @secret_code_hash = hash_with_default_array_value
12
10
  end
13
11
 
14
12
  def secret_code=(secret_code)
@@ -18,11 +16,11 @@ module Codebreaker
18
16
  def match?(guess)
19
17
  match(array_to_hash_of_positions(unify_code(guess)))
20
18
 
21
- bulls == 4
19
+ @bulls == 4
22
20
  end
23
21
 
24
22
  def marks
25
- marker.mark(bulls, cows)
23
+ marker.mark(@bulls, @cows)
26
24
  end
27
25
 
28
26
  private
@@ -33,17 +31,14 @@ module Codebreaker
33
31
 
34
32
  def array_to_hash_of_positions(array)
35
33
  array
36
- .each_with_object(hash_with_default_array_value)
34
+ .each_with_object({})
37
35
  .with_index do |(digit, hash), position|
36
+ hash[digit] ||= []
38
37
  hash[digit].push(position)
39
38
  hash
40
39
  end
41
40
  end
42
41
 
43
- def hash_with_default_array_value
44
- Hash.new { |h, digit| h[digit] = [] }
45
- end
46
-
47
42
  def match(guess_hash)
48
43
  @exact_matches = 0
49
44
  @all_matches = 0
@@ -55,12 +50,12 @@ module Codebreaker
55
50
  add_all_matches(digit, positions)
56
51
  end
57
52
 
58
- @bulls = exact_matches
59
- @cows = all_matches - exact_matches
53
+ @bulls = @exact_matches
54
+ @cows = @all_matches - @exact_matches
60
55
  end
61
56
 
62
57
  def digit_is_not_present_in_the_secret_code(digit)
63
- secret_code_hash[digit].empty?
58
+ secret_code_hash[digit] == nil
64
59
  end
65
60
 
66
61
  def add_exact_matches(digit, positions)
@@ -0,0 +1,7 @@
1
+ module Stats
2
+ def save_stat_in_file(stat_file, stats)
3
+ File.open(stat_file, 'a+') do |f|
4
+ f.write(stats.to_yaml)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module CodebreakerMats
2
- VERSION = "0.1.3"
2
+ VERSION = '0.1.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_mats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-25 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The app provides core for codebreaker game
14
14
  email:
@@ -17,9 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".circleci/config.yml"
21
+ - ".fasterer.yml"
20
22
  - ".gitignore"
21
23
  - ".rspec"
22
- - ".travis.yml"
24
+ - ".rubocop.yml"
25
+ - ".ruby-version"
26
+ - ".vscode/settings.json"
23
27
  - CODE_OF_CONDUCT.md
24
28
  - Gemfile
25
29
  - Gemfile.lock
@@ -32,11 +36,10 @@ files:
32
36
  - lib/codebreaker_mats.rb
33
37
  - lib/codebreaker_mats/exceptions/terminate_error.rb
34
38
  - lib/codebreaker_mats/game.rb
35
- - lib/codebreaker_mats/markers/classical_marker.rb
36
39
  - lib/codebreaker_mats/markers/plus_minus_marker.rb
37
40
  - lib/codebreaker_mats/matcher.rb
41
+ - lib/codebreaker_mats/stats.rb
38
42
  - lib/codebreaker_mats/version.rb
39
- - stat.yml
40
43
  homepage: https://github.com/Swooty18/codebreaker_mats.git
41
44
  licenses:
42
45
  - MIT
@@ -58,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
61
  - !ruby/object:Gem::Version
59
62
  version: '0'
60
63
  requirements: []
61
- rubygems_version: 3.1.3
64
+ rubygems_version: 3.1.4
62
65
  signing_key:
63
66
  specification_version: 4
64
67
  summary: codebreaker game
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreaker
4
- module Markers
5
- # Marker that will interpret the number of bulls
6
- # and cows in classical way.
7
- class ClassicalMarker
8
- def mark(bulls, cows)
9
- format('%d Bulls, %d Cows', bulls, cows)
10
- end
11
- end
12
- end
13
- end
data/stat.yml DELETED
File without changes