Class: GADDAG::Word
- Inherits:
-
Object
- Object
- GADDAG::Word
- Defined in:
- lib/gaddag/word.rb
Overview
Represents a word in the GADDAG data structure
Instance Attribute Summary collapse
-
#letters ⇒ Object
readonly
The letters that make up this word.
Instance Method Summary collapse
-
#initialize(letters) ⇒ Word
constructor
Initializes a GADDAG word the word consists.
-
#to_delimited_paths ⇒ Array<Path>
Constructs a list of delimited GADDAG paths from this word a delimiter, and a suffix: REV(PREFIX) ♢ SUFFIX.
-
#to_s ⇒ Object
Returns the word as string.
Constructor Details
#initialize(letters) ⇒ Word
Initializes a GADDAG word the word consists
17 18 19 |
# File 'lib/gaddag/word.rb', line 17 def initialize(letters) @letters = letters end |
Instance Attribute Details
#letters ⇒ Object (readonly)
The letters that make up this word
8 9 10 |
# File 'lib/gaddag/word.rb', line 8 def letters @letters end |
Instance Method Details
#to_delimited_paths ⇒ Array<Path>
Constructs a list of delimited GADDAG paths from this word a delimiter, and a suffix: REV(PREFIX) ♢ SUFFIX
30 31 32 33 34 35 36 |
# 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 ⇒ Object
Returns the word as string
23 24 25 |
# File 'lib/gaddag/word.rb', line 23 def to_s @letters.join end |