class GADDAG::Word
Represents a word in the GADDAG
data structure
Attributes
letters[R]
The letters that make up this word
Public Class Methods
new(letters)
click to toggle source
Initializes a GADDAG
word @param letters [Array<String>] an ordered list of letters of which the word consists @return [Word]
# File lib/gaddag/word.rb, line 17 def initialize(letters) @letters = letters end
Public Instance Methods
to_delimited_paths()
click to toggle source
Constructs a list of delimited GADDAG
paths from this word @return [Array<Path>] a list of paths, each containing a reversed prefix, a delimiter, and a suffix: REV(PREFIX) ♢ SUFFIX
# File lib/gaddag/word.rb, line 30 def to_delimited_paths 1.upto(letters.length - 1).map do |index| reversed_prefix = @letters.slice(0, index).reverse suffix = @letters.slice(index, @letters.count) Path.new(reversed_prefix + [Path::DELIMITER] + suffix) end end
to_s()
click to toggle source
Returns the word as string @return a string representation of the word
# File lib/gaddag/word.rb, line 23 def to_s @letters.join end