Class: Presentation

Inherits:
Object
  • Object
show all
Defined in:
lib/wee-pm/presentation.rb

Overview

A presentation is mainly a collection of slides.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Presentation

Returns a new instance of Presentation.

Yields:

  • (_self)

Yield Parameters:

  • _self (Presentation)

    the object that the method was called on



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

#authorObject

Returns the value of attribute author.



7
8
9
# File 'lib/wee-pm/presentation.rb', line 7

def author
  @author
end

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/wee-pm/presentation.rb', line 7

def email
  @email
end

#slidesObject (readonly)

Returns the value of attribute slides.



8
9
10
# File 'lib/wee-pm/presentation.rb', line 8

def slides
  @slides
end

#styleObject

Returns the value of attribute style.



7
8
9
# File 'lib/wee-pm/presentation.rb', line 7

def style
  @style
end

#titleObject

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 }
  slides = split_at(str, positions)

  new {|pres|
    pres.title = $1.strip if slides[0] =~ /^title::(.*)$/
    pres.author = $1.strip if slides[0] =~ /^author::(.*)$/
    pres.email = $1.strip if slides[0] =~ /^email::(.*)$/
    pres.style = $1.strip if slides[0] =~ /^style::(.*)^endstyle::$/m

    slides[1..-1].each do |s|
      pres.slides << 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_sObject



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