Module: Waylon::Wordle

Defined in:
lib/waylon/wordle.rb,
lib/waylon/wordle/solver.rb,
lib/waylon/wordle/version.rb

Overview

The Wordle module for Waylon

Defined Under Namespace

Classes: Error, Solver

Constant Summary collapse

VERSION =
"0.3.1"

Class Method Summary collapse

Class Method Details

.data_for_todayObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/waylon/wordle.rb', line 49

def self.data_for_today
  conn = Faraday.new(
    headers: {
      "User-Agent": "Waylon/Wordle",
      accept: "application/json",
      "Accept-Language": "en-US,en;q=0.5",
      referer: "https://www.nytimes.com/games/wordle/index.html"
    }
  )
  response = conn.get("https://www.nytimes.com/svc/wordle/v2/#{todays_date}.json")

  JSON.parse(response.body)
end

.for_todayObject



63
64
65
# File 'lib/waylon/wordle.rb', line 63

def self.for_today
  data_for_today["solution"]
end

.random_startwordObject



31
32
33
34
35
36
37
38
39
# File 'lib/waylon/wordle.rb', line 31

def self.random_startword
  vocabulary.select do |word|
    if rand(10) > 5
      word.chars.uniq.intersection(%w[a e i o u]).uniq.size >= 4
    else
      word.chars.uniq.intersection(%w[a e o s t r n]).uniq.size >= 4
    end
  end.sample
end

.todays_dateObject



41
42
43
# File 'lib/waylon/wordle.rb', line 41

def self.todays_date
  DateTime.now.new_offset("-05:00").to_date
end

.todays_numberObject



45
46
47
# File 'lib/waylon/wordle.rb', line 45

def self.todays_number
  (todays_date - Date.new(2021, 6, 19)).to_i
end

.vocabularyObject



27
28
29
# File 'lib/waylon/wordle.rb', line 27

def self.vocabulary
  @vocabulary ||= JSON.load_file(vocabulary_file)
end

.vocabulary_fileObject

Your code goes here…



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/waylon/wordle.rb', line 15

def self.vocabulary_file
  # First, try the official data path for the gem, then pull from a relative path
  relative_path = if File.exist?(Gem.datadir("waylon-wordle"))
                    Gem.datadir("waylon-wordle")
                  else
                    File.join(
                      File.dirname(__FILE__), "..", "..", "data"
                    )
                  end
  File.expand_path(File.join(relative_path, "vocabulary.json"))
end