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: Templates.for) ⇒ Presentation

Initialize a new presentation.



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

def initialize(slides = [], slides_root: nil, templates: Templates.for)
	@slides = slides
	@slides_root = slides_root
	@templates = templates
end

Instance Attribute Details

#slidesObject (readonly)

Returns the value of attribute slides.



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

def slides
  @slides
end

#slides_rootObject (readonly)

Returns the value of attribute slides_root.



44
45
46
# File 'lib/presently/presentation.rb', line 44

def slides_root
  @slides_root
end

#templatesObject (readonly)

Returns the value of attribute templates.



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

def templates
  @templates
end

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



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

attr :slides_root

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



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

attr :slides

Class Method Details

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

Load a presentation from a directory of Markdown slide files.



26
27
28
# File 'lib/presently/presentation.rb', line 26

def self.load(slides_root = "slides", **options)
	new(slides_from(slides_root), slides_root: slides_root, **options)
end

.slides_from(slides_root) ⇒ Object

Load and sort slide files from a directory.



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

def self.slides_from(slides_root)
	Dir.glob(File.join(slides_root, "*.md")).sort.map{|path| Slide.load(path)}.reject(&:skip?)
end

Instance Method Details

#expected_time_at(index) ⇒ Object

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



64
65
66
# File 'lib/presently/presentation.rb', line 64

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

#reloadObject

Return a new Presently::Presentation with freshly loaded slides and a cleared template cache. Only works if the presentation was created with load.



71
72
73
74
75
# File 'lib/presently/presentation.rb', line 71

def reload
	return self unless @slides_root
	
	self.class.new(self.class.slides_from(@slides_root), slides_root: @slides_root, templates: @templates.reload)
end

#slide_countObject

The number of slides in the presentation.



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

def slide_count
	@slides.length
end

#The template resolver.=(templateresolver. = (value)) ⇒ Object



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

attr :templates

#total_durationObject

The total expected duration of the presentation in seconds.



57
58
59
# File 'lib/presently/presentation.rb', line 57

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