wordle_cli 1.0.0

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.
data/lib/wordle_cli.rb ADDED
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "wordle_cli/version"
4
+ require_relative "wordle_cli/word_list"
5
+
6
+ module WordleCli
7
+ class Error < StandardError; end
8
+
9
+ def self.play(word = @@word_list.select { |word| word.length == 5 } .sample, guess: 6)
10
+ word = word.to_s if word.is_a?(Symbol)
11
+
12
+ word_length = word.is_a?(String) ? word.length : 0
13
+
14
+ if word.is_a?(Integer)
15
+ word_length = word
16
+ word = @@word_list.select { |word| word.length == word_length } .sample
17
+ end
18
+
19
+ guess_word_list = @@word_list.select { |word| word.length == word_length }
20
+
21
+ guess.times do |guess_count|
22
+ padding = guess.to_s.length + 1
23
+ guess_word = nil
24
+
25
+ loop do
26
+ print "\e[1m", ">".ljust(padding), "\e[m"
27
+ guess_word = gets.chomp.downcase
28
+
29
+ break if guess_word_list.include?(guess_word)
30
+
31
+ print "\e[A\e[?7l", " " * guess_word.size * 4, "\e[?7h\n\e[A"
32
+ end
33
+
34
+ print "\e[A\e[37m", (guess_count + 1).to_s.ljust(padding), "\e[m"
35
+
36
+ guess_word.chars.each_with_index do |char, index|
37
+ if char == word[index]
38
+ print "\e[0;1;30;102m"
39
+ elsif word.include? char
40
+ print "\e[0;30;103m"
41
+ else
42
+ print "\e[0;100m"
43
+ end
44
+
45
+ print "#{char}"
46
+ end
47
+
48
+ puts "\e[m"
49
+
50
+ return if guess_word == word
51
+ end
52
+
53
+ return word
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordle_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - NNB
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - nnbnh@protonmail.com
16
+ executables:
17
+ - wordle
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - exe/wordle
32
+ - lib/wordle_cli.rb
33
+ - lib/wordle_cli/version.rb
34
+ - lib/wordle_cli/word_list.rb
35
+ homepage: https://github.com/NNBnh/wordle_cli
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/NNBnh/wordle_cli
40
+ source_code_uri: https://github.com/NNBnh/wordle_cli
41
+ changelog_uri: https://github.com/NNBnh/wordle_cli/blob/main/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.6.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.2.26
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A simple CLI Wordle game.
61
+ test_files: []