Sha256: ca8be0418bf1fca754cf0deb7a34f3016f95669758d224dfe4a581369ecb9371
Contents?: true
Size: 651 Bytes
Versions: 239
Compression:
Stored size: 651 Bytes
Contents
module BookKeeping VERSION = 2 end class Anagram attr_reader :subject def initialize(word) @subject = AnagramSubject.new(word) end def match(candidates) candidates.select do |candidate| subject.anagram_of? candidate end end end class AnagramSubject attr_reader :subject def initialize(subject) @subject = subject end def anagram_of?(word) !duplicate?(word) && fingerprint == canonicalize(word) end def duplicate?(word) word.downcase == subject.downcase end def canonicalize(word) word.downcase.chars.sort end def fingerprint @fingerprint ||= canonicalize(subject) end end
Version data entries
239 entries across 239 versions & 1 rubygems