class Rungs::WordLadder

Public Class Methods

new(options = {}) click to toggle source
# File lib/rungs/word_ladder.rb, line 5
def initialize(options = {})
  options = {
    list: 'selected_four-letter_words.txt',
    steps: 1
  }.merge(options)

  load_options(:word, :list, options)
end

Public Instance Methods

call() click to toggle source
# File lib/rungs/word_ladder.rb, line 14
def call
  return result(true, ladder)
end

Private Instance Methods

ladder() click to toggle source
# File lib/rungs/word_ladder.rb, line 23
def ladder
  output = []

  words.each do |word|
    distance = 0

    word.chomp.chars.each_with_index do |character, i|
      distance += 1 unless character == @word[i]

      break if distance > @steps
    end

    output << word.chomp if distance <= @steps && distance > 0
  end

  output
end
words() click to toggle source
# File lib/rungs/word_ladder.rb, line 19
def words
  File.readlines(@list)
end