Class: Slideck::Tracker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/slideck/tracker.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for tracking current slide number

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current, total) ⇒ Tracker

Create a Tracker instance

Examples:

Slideck::Tracker.new(0, 11)

Parameters:

  • current (Integer)

    the current slide number

  • total (Integer)

    the total number of slides



54
55
56
57
58
59
# File 'lib/slideck/tracker.rb', line 54

def initialize(current, total)
  @current = current
  @total = total

  freeze
end

Instance Attribute Details

#currentInteger (readonly)

The current slide number

Examples:

tracker.current

Returns:

  • (Integer)


31
32
33
# File 'lib/slideck/tracker.rb', line 31

def current
  @current
end

#totalInteger (readonly)

The total number of slides

Examples:

tracker.total

Returns:

  • (Integer)


41
42
43
# File 'lib/slideck/tracker.rb', line 41

def total
  @total
end

Class Method Details

.for(total) ⇒ Slideck::Tracker

Create a Tracker instance with the current slide set to zero

Examples:

Slideck::Tracker.for(11)

Parameters:

  • total (Integer)

    the total number of slides

Returns:



19
20
21
# File 'lib/slideck/tracker.rb', line 19

def self.for(total)
  new(0, total)
end

Instance Method Details

#firstSlideck::Tracker

Move to the first slide

Examples:

tracker = tracker.first

Returns:



97
98
99
# File 'lib/slideck/tracker.rb', line 97

def first
  self.class.new(0, total)
end

#go_to(slide_no) ⇒ Slideck::Tracker

Go to a specific slide number

Examples:

tracker = tracker.go_to(5)

Parameters:

  • slide_no (Integer)

    the slide number

Returns:



124
125
126
127
128
# File 'lib/slideck/tracker.rb', line 124

def go_to(slide_no)
  return self if slide_no < 0 || total - 1 < slide_no

  self.class.new(slide_no, total)
end

#lastSlideck::Tracker

Move to the last slide

Examples:

tracker = tracker.last

Returns:



109
110
111
# File 'lib/slideck/tracker.rb', line 109

def last
  self.class.new(total - 1, total)
end

#nextSlideck::Tracker

Move to the next slide

Examples:

tracker = tracker.next

Returns:



69
70
71
72
73
# File 'lib/slideck/tracker.rb', line 69

def next
  return self if current >= total - 1

  self.class.new(current + 1, total)
end

#previousSlideck::Tracker

Move to the previous slide

Examples:

tracker = tracker.previous

Returns:



83
84
85
86
87
# File 'lib/slideck/tracker.rb', line 83

def previous
  return self if current.zero?

  self.class.new(current - 1, total)
end

#resize(new_total) ⇒ Slideck::Tracker

Resize to the new total

Examples:

tracker = tracker.resize(10)

Parameters:

  • new_total (Integer)

    the new total

Returns:



141
142
143
144
145
# File 'lib/slideck/tracker.rb', line 141

def resize(new_total)
  return self if new_total < 0 || total == new_total

  self.class.new(reset_current(new_total), new_total)
end