Class: Presently::Presentation

Inherits:
Object
  • Object
show all
Defined in:
lib/presently/presentation.rb

Overview

An immutable collection of slides with configuration.

Use Presentation.load to create a presentation from a directory of Markdown files, or initialize directly with an array of Slide instances.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slides = [], slides_root: nil, templates_root: nil) ⇒ Presentation

Initialize a new presentation.



29
30
31
32
33
# File 'lib/presently/presentation.rb', line 29

def initialize(slides = [], slides_root: nil, templates_root: nil)
	@slides = slides
	@slides_root = slides_root
	@templates_root = templates_root
end

Instance Attribute Details

#slidesObject (readonly)

Returns the value of attribute slides.



36
37
38
# File 'lib/presently/presentation.rb', line 36

def slides
  @slides
end

#slides_rootObject (readonly)

Returns the value of attribute slides_root.



39
40
41
# File 'lib/presently/presentation.rb', line 39

def slides_root
  @slides_root
end

#templates_rootObject (readonly)

Returns the value of attribute templates_root.



42
43
44
# File 'lib/presently/presentation.rb', line 42

def templates_root
  @templates_root
end

#The directory containing custom templates.(directorycontainingcustomtemplates.) ⇒ Object (readonly)



42
# File 'lib/presently/presentation.rb', line 42

attr :templates_root

#The directory slides were loaded from.(directoryslideswereloadedfrom.) ⇒ Object (readonly)



39
# File 'lib/presently/presentation.rb', line 39

attr :slides_root

#The ordered list of slides.(orderedlistofslides.) ⇒ Object (readonly)



36
# File 'lib/presently/presentation.rb', line 36

attr :slides

Class Method Details

.load(slides_root = "slides", **options) ⇒ Object

Load a presentation from a directory of Markdown slide files.



18
19
20
21
22
23
# File 'lib/presently/presentation.rb', line 18

def self.load(slides_root = "slides", **options)
	pattern = File.join(slides_root, "*.md")
	slides = Dir.glob(pattern).sort.map{|path| Slide.new(path)}
	
	new(slides, slides_root: slides_root, **options)
end

Instance Method Details

#expected_time_at(index) ⇒ Object

Calculate the expected elapsed time for slides up to the given index.



59
60
61
# File 'lib/presently/presentation.rb', line 59

def expected_time_at(index)
	@slides[0...index].sum(&:duration)
end

#reload!Object

Reload slides from the original directory. Only works if the presentation was created with load.



65
66
67
68
69
70
# File 'lib/presently/presentation.rb', line 65

def reload!
	if @slides_root
		pattern = File.join(@slides_root, "*.md")
		@slides = Dir.glob(pattern).sort.map{|path| Slide.new(path)}
	end
end

#slide_countObject

The number of slides in the presentation.



46
47
48
# File 'lib/presently/presentation.rb', line 46

def slide_count
	@slides.length
end

#total_durationObject

The total expected duration of the presentation in seconds.



52
53
54
# File 'lib/presently/presentation.rb', line 52

def total_duration
	@slides.sum(&:duration)
end