gem_codebreaker_amidasd 0.1.4 → 0.1.5

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: 7e77ad8ddcc4a654b246b2a75687058183c18ead8da0a1c4684b351efefd91fb
4
- data.tar.gz: 28a1b6c88964675e67e288018ad68c4ee4f31d720f2bedd728e889226b150eb9
3
+ metadata.gz: 65f81d2ecb7263634807f5d042e8d513534dcf7420dd8469e77672078860060b
4
+ data.tar.gz: c30e98b582e54cf7adea32993e74e9033359b532183a98de51f95b6a2025b2a0
5
5
  SHA512:
6
- metadata.gz: c883f90bb0d368193a80252a6cf42f3c802c6755b4d47b7c0918dda12c68afb0315311cd8e1a6de5a6dcd470a8b9da414c0d72bf4b537a0b979f05b01109fa35
7
- data.tar.gz: 950ff4723d9c63f4c19d042bd1ce0e175b13e3dfaf212ad69def8962d3a9d889ba4a4f165ec0509d09438a897b81ff4dbbe2a05a10410dcfdaf2769d01f0457f
6
+ metadata.gz: 3677c98735935df4d0cb7b48c864a59489138eec00bc7370aa54ae4fe4a2c5927f4087710840a352416d1d9ef4cbd2484aa26b91c21e4be55f836b2b6a6efe6e
7
+ data.tar.gz: d5d987b906b62309208b98ca1339c29cd867809e6ff468d873a006e9bee5fd549748af18aab2c341868c2ffa0bfe7ebe11ce5153650ad329ef5e93d7b85fb786
@@ -1,11 +1,4 @@
1
1
  require 'gem_codebreaker_amidasd/version'
2
- require 'gem_codebreaker_amidasd/gem_codebreaker'
3
2
  require 'gem_codebreaker_amidasd/db_utility'
4
3
  require 'gem_codebreaker_amidasd/user'
5
- require 'gem_codebreaker_amidasd/version'
6
-
7
- # Dir[Dir.pwd + './gem_codebreaker_amidasd/**/*.rb'].sort.reverse_each { |f| require f }
8
- # module GemCodebreakerAmidasd
9
- # # class Error < StandardError; end
10
- # #
11
- # # end
4
+ require 'gem_codebreaker_amidasd/gem_codebreaker'
@@ -1,25 +1,25 @@
1
1
  module GemCodebreakerAmidasd
2
- class DbUtility
3
- class << self
4
- def save_yaml_db(user, yml_db)
5
- # yml_db = CodebreakerConfig::PATH_DB
6
- File.write(yml_db, user.to_yaml)
7
- end
2
+ require 'yaml'
8
3
 
9
- def load_yaml_db(yml_db)
10
- # yml_db = CodebreakerConfig::PATH_DB
11
- return unless File.exist?(yml_db)
4
+ class DbUtility
5
+ class << self
6
+ def save_yaml_db(user, yml_db)
7
+ File.write(yml_db, user.to_yaml)
8
+ end
12
9
 
13
- YAML.load_file(yml_db)
14
- end
10
+ def load_yaml_db(yml_db)
11
+ return unless File.exist?(yml_db)
12
+
13
+ YAML.load_file(yml_db)
14
+ end
15
15
 
16
- def add_db(user, path)
17
- db = load_yaml_db(path)
18
- db ||= []
19
- db << (user)
20
- db = db.sort_by { |value| [value.total_count_attempt, value.count_attempt, value.count_hint] }
21
- save_yaml_db(db, path)
16
+ def add_db(user, path)
17
+ db = load_yaml_db(path)
18
+ db ||= []
19
+ db << user
20
+ db = db.sort_by { |value| [value.total_count_attempt, value.count_attempt, value.count_hint] }
21
+ save_yaml_db(db, path)
22
+ end
22
23
  end
23
24
  end
24
25
  end
25
- end
@@ -1,10 +1,9 @@
1
1
  module GemCodebreakerAmidasd
2
- DIFFICULTY_HASH = {:easy => { total_count_attempt: 15, total_count_hints: 2 },
3
- :medium => { total_count_attempt: 10, total_count_hints: 1 },
4
- :hell => { total_count_attempt: 5, total_count_hints: 1 }}
2
+ DIFFICULTY_HASH = { easy: { total_count_attempt: 15, total_count_hints: 2 },
3
+ medium: { total_count_attempt: 10, total_count_hints: 1 },
4
+ hell: { total_count_attempt: 5, total_count_hints: 1 } }.freeze
5
5
 
6
6
  class GemCodebreaker
7
-
8
7
  attr_accessor :difficulty_hash, :difficulty
9
8
  attr_accessor :length_code, :max_num, :min_num
10
9
  attr_reader :total_count_attempt, :total_count_hints, :error, :win, :count_plus, :count_minus, :hint
@@ -21,12 +20,13 @@ module GemCodebreakerAmidasd
21
20
  empty_result
22
21
  end
23
22
 
24
- def string_secertcode
23
+ def string_secretcode
25
24
  @secret_code.join('')
26
25
  end
27
26
 
28
27
  def set_difficulty(difficulty)
29
- return unless @difficulty_hash.has_key? difficulty
28
+ return unless @difficulty_hash.key? difficulty
29
+
30
30
  @difficulty = difficulty
31
31
  @total_count_attempt = @difficulty_hash[difficulty][:total_count_attempt]
32
32
  @total_count_hints = @difficulty_hash[difficulty][:total_count_hints]
@@ -71,17 +71,17 @@ module GemCodebreakerAmidasd
71
71
  def search_hint
72
72
  cache_array = []
73
73
  @secret_code.each { |val| cache_array << val if !@array_hints.include?(val) && !cache_array.include?(val) }
74
- @error = 'HintsEnd' unless @total_count_hints > @array_hints.size
75
- @error = 'NoCluesAvailable' if cache_array.empty?
74
+ @error = :HintsEnd unless @total_count_hints > @array_hints.size
75
+ @error = :NoCluesAvailable if cache_array.empty?
76
76
  cache_array
77
77
  end
78
78
 
79
79
  def check_code(code_attempt)
80
80
  correct_code = to_array(code_attempt)
81
81
  empty_result
82
- @error = 'WrongCode' unless code_attempt.match(/[1-6]+$/)
83
- @error = 'WrongCode' unless correct_code.size == @length_code
84
- return nil if @error == 'WrongCode'
82
+ @error = :WrongCode unless code_attempt.match(/[1-6]+$/)
83
+ @error = :WrongCode unless correct_code.size == @length_code
84
+ return nil if @error == :WrongCode
85
85
 
86
86
  status_game(correct_code)
87
87
  @count_attempt += 1
@@ -1,27 +1,26 @@
1
1
  module GemCodebreakerAmidasd
2
- class User
3
- attr_accessor :name,
4
- :difficulty,
5
- :total_count_attempt,
6
- :count_attempt,
7
- :total_count_hints,
8
- :count_hint
2
+ class User
3
+ attr_accessor :name,
4
+ :difficulty,
5
+ :total_count_attempt,
6
+ :count_attempt,
7
+ :total_count_hints,
8
+ :count_hint
9
9
 
10
- def initialize(name:)
11
- @name = name
12
- end
10
+ def initialize(name:)
11
+ @name = name
12
+ end
13
13
 
14
- def set_params(difficulty:, total_count_attempt:, count_attempt:, total_count_hints:,count_hint:)
15
- @difficulty = difficulty
16
- @total_count_attempt = total_count_attempt
17
- @count_attempt = count_attempt
18
- @total_count_hints = total_count_hints
19
- @count_hint = count_hint
20
- end
14
+ def set_params(difficulty:, total_count_attempt:, count_attempt:, total_count_hints:, count_hint:)
15
+ @difficulty = difficulty
16
+ @total_count_attempt = total_count_attempt
17
+ @count_attempt = count_attempt
18
+ @total_count_hints = total_count_hints
19
+ @count_hint = count_hint
20
+ end
21
21
 
22
- def self.validtion_name(name)
23
- name.is_a?(String) && !name.empty? && name.length.between?(3, 20)
22
+ def self.validtion_name(name)
23
+ name.is_a?(String) && !name.empty? && name.length.between?(3, 20)
24
+ end
24
25
  end
25
-
26
26
  end
27
- end
@@ -1,3 +1,3 @@
1
1
  module GemCodebreakerAmidasd
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_codebreaker_amidasd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amidasd
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-12 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - gem_codebreaker_amidasd-0.1.1.gem
133
133
  - gem_codebreaker_amidasd-0.1.2.gem
134
134
  - gem_codebreaker_amidasd-0.1.3.gem
135
+ - gem_codebreaker_amidasd-0.1.4.gem
135
136
  - gem_codebreaker_amidasd.gemspec
136
137
  - lib/gem_codebreaker_amidasd.rb
137
138
  - lib/gem_codebreaker_amidasd/db_utility.rb