Class: EhbGameLib::Utils::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/utils/cursor.rb

Instance Method Summary collapse

Constructor Details

#initialize(set) ⇒ Cursor

Returns a new instance of Cursor.



6
7
8
9
# File 'lib/ehb_game_lib/utils/cursor.rb', line 6

def initialize(set)
  @set = set.to_a
  @index = nil
end

Instance Method Details

#currentObject



25
26
27
# File 'lib/ehb_game_lib/utils/cursor.rb', line 25

def current
  index.nil? ? nil : @set[index]
end

#indexObject



29
30
31
32
# File 'lib/ehb_game_lib/utils/cursor.rb', line 29

def index
  fix_index
  @index
end

#next_elementObject



17
18
19
# File 'lib/ehb_game_lib/utils/cursor.rb', line 17

def next_element
  next_previous_element(1)
end

#previous_elementObject



21
22
23
# File 'lib/ehb_game_lib/utils/cursor.rb', line 21

def previous_element
  next_previous_element(-1)
end

#select_lastObject



13
14
15
# File 'lib/ehb_game_lib/utils/cursor.rb', line 13

def select_last
  self.index = @set.length - 1
end