Class: Presentation
- Inherits:
-
Object
- Object
- Presentation
- Defined in:
- lib/wee-pm/presentation.rb
Overview
A presentation is mainly a collection of slides.
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#email ⇒ Object
Returns the value of attribute email.
-
#slides ⇒ Object
readonly
Returns the value of attribute slides.
-
#style ⇒ Object
Returns the value of attribute style.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Presentation
constructor
A new instance of Presentation.
- #save(filename) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Presentation
Returns a new instance of Presentation.
35 36 37 38 39 40 41 42 |
# File 'lib/wee-pm/presentation.rb', line 35 def initialize @title = 'unnamed presentation' @author = '' @email = '' @style = '' @slides = [] yield self if block_given? end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
7 8 9 |
# File 'lib/wee-pm/presentation.rb', line 7 def @author end |
#email ⇒ Object
Returns the value of attribute email.
7 8 9 |
# File 'lib/wee-pm/presentation.rb', line 7 def email @email end |
#slides ⇒ Object (readonly)
Returns the value of attribute slides.
8 9 10 |
# File 'lib/wee-pm/presentation.rb', line 8 def @slides end |
#style ⇒ Object
Returns the value of attribute style.
7 8 9 |
# File 'lib/wee-pm/presentation.rb', line 7 def style @style end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/wee-pm/presentation.rb', line 7 def title @title end |
Class Method Details
.from_string(str) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wee-pm/presentation.rb', line 11 def from_string(str) positions = [0] str.scan(/^=([^=].*)$/) { positions << $~.offset(0).first } = split_at(str, positions) new {|pres| pres.title = $1.strip if [0] =~ /^title::(.*)$/ pres. = $1.strip if [0] =~ /^author::(.*)$/ pres.email = $1.strip if [0] =~ /^email::(.*)$/ pres.style = $1.strip if [0] =~ /^style::(.*)^endstyle::$/m [1..-1].each do |s| pres. << Slide.from_string(s) end } end |
Instance Method Details
#save(filename) ⇒ Object
62 63 64 |
# File 'lib/wee-pm/presentation.rb', line 62 def save(filename) File.open(filename, 'w+') {|f| f << self.to_s } end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wee-pm/presentation.rb', line 44 def to_s str = "title:: #{ @title }\n" + "author:: #{ @author }\n" + "email:: #{ @email }\n" unless @style.strip.empty? str << "style::\n" str << @style str << "\n" str << "endstyle::\n" end str << "\n" @slides.each { |s| str << s.to_s } str.gsub!("\r\n", "\n") str end |