Sha256: 93c0627d3795b8d84943d94af9e86d42e0417b957b9f58bc8a65fe333b591310

Contents?: true

Size: 536 Bytes

Versions: 2

Compression:

Stored size: 536 Bytes

Contents

# frozen_string_literal: true

module Wordle
  class List
    def initialize(length = 5)
      @length = length
    end

    def random
      list.sample.downcase.strip
    end

    def invalid?(word)
      !list.include?(word)
    end

    private

    def list
      # fall back to api if this fails?
      @_list ||= begin
        File.readlines("/usr/share/dict/words").select do |word|
          word.strip.length == @length
        end.map { |w| w.downcase.strip } # sanitize class to standarize this?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wordle-0.1.1 lib/wordle/list.rb
wordle-0.1.0 lib/wordle/list.rb