Sha256: f31ea9160a7370c31765ab784a823fe874fb8f88957efa847b28ba2a2065b781

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require "date"
require "json"

require "waylon/core"
require_relative "wordle/version"

module Waylon
  # The Wordle module for Waylon
  module Wordle
    class Error < StandardError; end
    # Your code goes here...

    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

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

    def self.random_startword
      vocabulary.select { |word| word.chars.intersection(%w[a e i o u]).uniq.size >= 3 }.sample
    end

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

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

    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

    def self.for_today
      data_for_today["solution"]
    end
  end
end

require_relative "wordle/solver"
require_relative "skills/wordle"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
waylon-wordle-0.3.0 lib/waylon/wordle.rb
waylon-wordle-0.2.0 lib/waylon/wordle.rb
waylon-wordle-0.1.2 lib/waylon/wordle.rb