new_super_codebreaker_2021 0.4.5 → 0.4.9

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
  SHA256:
3
- metadata.gz: e6e66f5272359e959f412ca6dc0d7363d7ede198844dcdbcd9878701b90347cf
4
- data.tar.gz: 450d2f983d577a9ccc0c979cb29b8ae8364c3542d809db80dec89482910604c5
3
+ metadata.gz: 4a45867c0685da262332ee817796e564c8944d6af38aa4c258b824ea42f88f24
4
+ data.tar.gz: '0815f455e9c28adbce6b1040c08208430ada9ac5647dac40ada7588f90a46502'
5
5
  SHA512:
6
- metadata.gz: 15def3bd39bf2b810370cf2310d1ac613013a3179da4565459214f2533fe057222b16b4f27bbea189e236f13f4eb022cce560c8983420c0f5a7fa41ff89392f1
7
- data.tar.gz: 12586743080a5fc9dff5b8e32155f327a95de55ca7355f982f70b530f548daadc8098c268777a78bc6e35a631d7febe1e8d1da309fd933ca272863e388640fae
6
+ metadata.gz: 38351e45906fa5a0f99aae6f5e45b4a9b0f481fdb9913605447b5abea9b993beca5a72618342c29087800354254c06215d455c8f1aee0bb492dd987699d91952
7
+ data.tar.gz: 4dc02b5a06f89940c19ad6beeee2e2088ce484843616a176fa3915bcf6db11c7571e3dc61037d4535fc2a21fadab85920ca8905a4f184ca6c5ea55d1dc23cd8e
@@ -0,0 +1,17 @@
1
+ module NewSuperCodebreaker2021
2
+ module DBMethods
3
+ def save(user, file)
4
+ rating = load_file(file)
5
+ rating.push(user)
6
+ File.open(file, 'w') do |filename|
7
+ YAML.dump(rating, filename)
8
+ end
9
+ end
10
+
11
+ def load_file(file)
12
+ YAML.load_file(file)
13
+ rescue Errno::ENOENT
14
+ []
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,10 @@
1
- require 'yaml'
2
- require_relative 'validate'
3
- require_relative 'show_content'
4
- require_relative 'db_methods'
5
- require_relative 'user'
6
1
  module NewSuperCodebreaker2021
7
2
  class Game
8
- attr_reader :code
9
-
10
- include Validate
11
- include ShowContent
12
3
  include DBMethods
4
+ include ShowContent
5
+ include Validate
6
+
7
+ attr_reader :code
13
8
 
14
9
  def initialize
15
10
  @code = generate_code
@@ -0,0 +1,10 @@
1
+ module NewSuperCodebreaker2021
2
+ module ShowContent
3
+ def show_stats(file)
4
+ data = YAML.load_file(file) || []
5
+ data.sort_by! { |game| [-game.difficulty, game.attempts_used, game.hints_used] }
6
+ rescue Errno::ENOENT
7
+ []
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module NewSuperCodebreaker2021
2
+ class User
3
+ attr_reader :name, :difficulty, :hints_total, :attempts_total
4
+ attr_accessor :hints_used, :attempts_used
5
+
6
+ DIFFICULTY = {
7
+ easy: { attempts: 15, hints: 2 },
8
+ medium: { attempts: 10, hints: 1 },
9
+ hell: { attempts: 5, hints: 1 }
10
+ }.freeze
11
+
12
+ def initialize(name, difficulty)
13
+ @name = name
14
+ @difficulty = difficulty
15
+ @hints_used = 0
16
+ @attempts_used = 0
17
+ set_total_fields
18
+ end
19
+
20
+ private
21
+
22
+ def set_total_fields
23
+ difficulty = DIFFICULTY.keys[@difficulty]
24
+ @hints_total = DIFFICULTY[difficulty][:hints]
25
+ @attempts_total = DIFFICULTY[difficulty][:attempts]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ module NewSuperCodebreaker2021
2
+ module Validate
3
+ def validate_name(name)
4
+ name if valid_name?(name)
5
+ end
6
+
7
+ def validate_user_code(us_code)
8
+ arr_code = split_to_integer_array(us_code)
9
+ return unless valid_number?(arr_code)
10
+
11
+ arr_code
12
+ end
13
+
14
+ def check_input(input, command_list)
15
+ return unless valid_input?(input, command_list)
16
+
17
+ input.to_sym
18
+ end
19
+
20
+ private
21
+
22
+ def valid_input?(input, command_list)
23
+ input.to_i.zero? && command_list.include?(input.to_sym)
24
+ end
25
+
26
+ def valid_number?(arr_code)
27
+ arr_code && check_code_length?(arr_code) && check_numbers?(arr_code)
28
+ end
29
+
30
+ def split_to_integer_array(code)
31
+ code.chars.map!(&:to_i) if integer?(code)
32
+ end
33
+
34
+ def integer?(code)
35
+ code.to_i.to_s == code
36
+ end
37
+
38
+ def check_code_length?(code)
39
+ code.length == 4
40
+ end
41
+
42
+ def check_numbers?(code)
43
+ code.all? { |value| value.between?(1, 6) }
44
+ end
45
+
46
+ def valid_name?(name)
47
+ name.length >= 3 && name.length <= 20
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module NewSuperCodebreaker2021
4
- VERSION = '0.4.5'
2
+ VERSION = '0.4.9'.freeze
5
3
  end
@@ -1,6 +1,7 @@
1
- require_relative 'new_super_codebreaker_2021/version'
2
- require 'game'
3
-
4
- module NewSuperCodebreaker2021
5
- class Error < StandardError; end
6
- end
1
+ require 'yaml'
2
+ require_relative 'new_super_codebreaker_2021/user'
3
+ require_relative 'new_super_codebreaker_2021/show_content'
4
+ require_relative 'new_super_codebreaker_2021/db_methods'
5
+ require_relative 'new_super_codebreaker_2021/validate'
6
+ require_relative 'new_super_codebreaker_2021/game'
7
+ require_relative 'new_super_codebreaker_2021/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_super_codebreaker_2021
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nazar Dakhno
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -115,21 +115,14 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - CHANGELOG.md
119
- - CODE_OF_CONDUCT.md
120
- - Gemfile
121
- - Gemfile.lock
122
118
  - README.md
123
- - Rakefile
124
- - bin/console
125
- - bin/setup
126
- - lib/db_methods.rb
127
- - lib/game.rb
128
119
  - lib/new_super_codebreaker_2021.rb
120
+ - lib/new_super_codebreaker_2021/db_methods.rb
121
+ - lib/new_super_codebreaker_2021/game.rb
122
+ - lib/new_super_codebreaker_2021/show_content.rb
123
+ - lib/new_super_codebreaker_2021/user.rb
124
+ - lib/new_super_codebreaker_2021/validate.rb
129
125
  - lib/new_super_codebreaker_2021/version.rb
130
- - lib/show_content.rb
131
- - lib/user.rb
132
- - lib/validate.rb
133
126
  homepage: https://rubygems.org/gems/new_super_codebreaker_2021
134
127
  licenses:
135
128
  - MIT
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2021-08-17
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at dakhnonazar@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in new_super_codebreaker_2021.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,76 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- new_super_codebreaker_2021 (0.4.4)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.2)
10
- colorize (0.8.1)
11
- diff-lcs (1.4.4)
12
- docile (1.4.0)
13
- fasterer (0.9.0)
14
- colorize (~> 0.7)
15
- ruby_parser (>= 3.14.1)
16
- ffaker (2.19.0)
17
- parallel (1.20.1)
18
- parser (3.0.2.0)
19
- ast (~> 2.4.1)
20
- rainbow (3.0.0)
21
- rake (13.0.6)
22
- regexp_parser (2.1.1)
23
- rexml (3.2.5)
24
- rspec (3.10.0)
25
- rspec-core (~> 3.10.0)
26
- rspec-expectations (~> 3.10.0)
27
- rspec-mocks (~> 3.10.0)
28
- rspec-core (3.10.1)
29
- rspec-support (~> 3.10.0)
30
- rspec-expectations (3.10.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.10.0)
33
- rspec-mocks (3.10.2)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.10.0)
36
- rspec-support (3.10.2)
37
- rubocop (1.19.1)
38
- parallel (~> 1.10)
39
- parser (>= 3.0.0.0)
40
- rainbow (>= 2.2.2, < 4.0)
41
- regexp_parser (>= 1.8, < 3.0)
42
- rexml
43
- rubocop-ast (>= 1.9.1, < 2.0)
44
- ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 3.0)
46
- rubocop-ast (1.10.0)
47
- parser (>= 3.0.1.1)
48
- ruby-progressbar (1.11.0)
49
- ruby_parser (3.17.0)
50
- sexp_processor (~> 4.15, >= 4.15.1)
51
- sexp_processor (4.15.3)
52
- simplecov (0.21.2)
53
- docile (~> 1.1)
54
- simplecov-html (~> 0.11)
55
- simplecov_json_formatter (~> 0.1)
56
- simplecov-html (0.12.3)
57
- simplecov_json_formatter (0.1.3)
58
- terminal-table (3.0.1)
59
- unicode-display_width (>= 1.1.1, < 3)
60
- unicode-display_width (2.0.0)
61
-
62
- PLATFORMS
63
- x86_64-linux
64
-
65
- DEPENDENCIES
66
- fasterer (~> 0.9.0)
67
- ffaker
68
- new_super_codebreaker_2021!
69
- rake (~> 13.0)
70
- rspec (~> 3.10.0)
71
- rubocop (~> 1.7)
72
- simplecov (~> 0.21.2)
73
- terminal-table (~> 3.0.1)
74
-
75
- BUNDLED WITH
76
- 2.2.26
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rubocop/rake_task'
3
-
4
- begin
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec)
7
- rescue LoadError
8
- # Ignored
9
- end
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'new_super_codebreaker_2021'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/db_methods.rb DELETED
@@ -1,15 +0,0 @@
1
- module DBMethods
2
- def save(user, file)
3
- rating = load_file(file)
4
- rating.push(user)
5
- File.open(file, 'w') do |filename|
6
- YAML.dump(rating, filename)
7
- end
8
- end
9
-
10
- def load_file(file)
11
- YAML.load_file(file)
12
- rescue Errno::ENOENT
13
- []
14
- end
15
- end
data/lib/show_content.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'terminal-table'
2
-
3
- module ShowContent
4
- def show_stats(file)
5
- data = YAML.load_file(file) || []
6
- data.sort_by! { |game| [-game.difficulty, game.attempts_used, game.hints_used] }
7
- rescue Errno::ENOENT
8
- []
9
- end
10
- end
data/lib/user.rb DELETED
@@ -1,28 +0,0 @@
1
- require_relative 'show_content'
2
-
3
- class User
4
- attr_reader :name, :difficulty, :hints_total, :attempts_total
5
- attr_accessor :hints_used, :attempts_used
6
-
7
- DIFFICULTY = {
8
- easy: { attempts: 15, hints: 2 },
9
- medium: { attempts: 10, hints: 1 },
10
- hell: { attempts: 5, hints: 1 }
11
- }.freeze
12
-
13
- def initialize(name, difficulty)
14
- @name = name
15
- @difficulty = difficulty
16
- @hints_used = 0
17
- @attempts_used = 0
18
- set_total_fields
19
- end
20
-
21
- private
22
-
23
- def set_total_fields
24
- difficulty = DIFFICULTY.keys[@difficulty]
25
- @hints_total = DIFFICULTY[difficulty][:hints]
26
- @attempts_total = DIFFICULTY[difficulty][:attempts]
27
- end
28
- end
data/lib/validate.rb DELETED
@@ -1,48 +0,0 @@
1
- module Validate
2
- def validate_name(name)
3
- name if valid_name?(name)
4
- end
5
-
6
- def validate_user_code(us_code)
7
- arr_code = split_to_integer_array(us_code)
8
- return unless valid_number?(arr_code)
9
-
10
- arr_code
11
- end
12
-
13
- def check_input(input, command_list)
14
- return unless valid_input?(input, command_list)
15
-
16
- input.to_sym
17
- end
18
-
19
- private
20
-
21
- def valid_input?(input, command_list)
22
- input.to_i.zero? && command_list.include?(input.to_sym)
23
- end
24
-
25
- def valid_number?(arr_code)
26
- arr_code && check_code_length?(arr_code) && check_numbers?(arr_code)
27
- end
28
-
29
- def split_to_integer_array(code)
30
- code.chars.map!(&:to_i) if integer?(code)
31
- end
32
-
33
- def integer?(code)
34
- code.to_i.to_s == code
35
- end
36
-
37
- def check_code_length?(code)
38
- code.length == 4
39
- end
40
-
41
- def check_numbers?(code)
42
- code.all? { |value| value.between?(1, 6) }
43
- end
44
-
45
- def valid_name?(name)
46
- name.length >= 3 && name.length <= 20
47
- end
48
- end