Class: Presently::Presentation
- Inherits:
-
Object
- Object
- Presently::Presentation
- 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
-
#slides ⇒ Object
readonly
Returns the value of attribute slides.
-
#slides_root ⇒ Object
readonly
Returns the value of attribute slides_root.
-
#templates_root ⇒ Object
readonly
Returns the value of attribute templates_root.
- #The directory containing custom templates.(directorycontainingcustomtemplates.) ⇒ Object readonly
- #The directory slides were loaded from.(directoryslideswereloadedfrom.) ⇒ Object readonly
- #The ordered list of slides.(orderedlistofslides.) ⇒ Object readonly
Class Method Summary collapse
-
.load(slides_root = "slides", **options) ⇒ Object
Load a presentation from a directory of Markdown slide files.
Instance Method Summary collapse
-
#expected_time_at(index) ⇒ Object
Calculate the expected elapsed time for slides up to the given index.
-
#initialize(slides = [], slides_root: nil, templates_root: nil) ⇒ Presentation
constructor
Initialize a new presentation.
-
#reload! ⇒ Object
Reload slides from the original directory.
-
#slide_count ⇒ Object
The number of slides in the presentation.
-
#total_duration ⇒ Object
The total expected duration of the presentation in seconds.
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_root: nil, templates_root: nil) @slides = @slides_root = @templates_root = templates_root end |
Instance Attribute Details
#slides ⇒ Object (readonly)
Returns the value of attribute slides.
36 37 38 |
# File 'lib/presently/presentation.rb', line 36 def @slides end |
#slides_root ⇒ Object (readonly)
Returns the value of attribute slides_root.
39 40 41 |
# File 'lib/presently/presentation.rb', line 39 def @slides_root end |
#templates_root ⇒ Object (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", **) pattern = File.join(, "*.md") = Dir.glob(pattern).sort.map{|path| Slide.new(path)} new(, slides_root: , **) 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_count ⇒ Object
The number of slides in the presentation.
46 47 48 |
# File 'lib/presently/presentation.rb', line 46 def @slides.length end |
#total_duration ⇒ Object
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 |