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.



4
5
6
7
# File 'lib/ehb_game_lib/utils/cursor.rb', line 4

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

Instance Method Details

#currentObject



23
24
25
# File 'lib/ehb_game_lib/utils/cursor.rb', line 23

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

#indexObject



27
28
29
30
# File 'lib/ehb_game_lib/utils/cursor.rb', line 27

def index
  fix_index
  @index
end

#next_elementObject



15
16
17
# File 'lib/ehb_game_lib/utils/cursor.rb', line 15

def next_element
  next_previous_element(1)
end

#previous_elementObject



19
20
21
# File 'lib/ehb_game_lib/utils/cursor.rb', line 19

def previous_element
  next_previous_element(-1)
end

#select_lastObject



11
12
13
# File 'lib/ehb_game_lib/utils/cursor.rb', line 11

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