Class: DialogTui::Neighbors

Inherits:
Object
  • Object
show all
Defined in:
lib/dialog_tui/neighbors.rb

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Neighbors

Returns a new instance of Neighbors.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dialog_tui/neighbors.rb', line 4

def initialize array
  neighbors =\
    array.zip( array.rotate, array.rotate(-1) )

  keys_values =\
    neighbors.map { |entry, nexxt, prev|
      [
        entry,  # key
        { next: nexxt, prev: prev }  # value
      ]
    }

  @neighbors_of = Hash[keys_values]
end

Instance Method Details

#next(from) ⇒ Object



19
20
21
# File 'lib/dialog_tui/neighbors.rb', line 19

def next from
  neighbors(from)[:next]
end

#prev(from) ⇒ Object



23
24
25
# File 'lib/dialog_tui/neighbors.rb', line 23

def prev from
  neighbors(from)[:prev]
end