Class: RubyPoint::Presentation

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

Defined Under Namespace

Classes: Presentation

Constant Summary collapse

@@base_pptx =
File.dirname(__FILE__)+'/base.pptx'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path = @@base_pptx) ⇒ Presentation

Returns a new instance of Presentation.



9
10
11
12
13
14
15
# File 'lib/rubypoint/presentation.rb', line 9

def initialize(file_path=@@base_pptx)
  @working_directory = RubyPoint.working_directory
  @uuid = Time.now.to_i + rand(100)
  @files = []
  @base_file_name = file_path.split('/').last
  self.open(file_path)
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



7
8
9
# File 'lib/rubypoint/presentation.rb', line 7

def files
  @files
end

#slidesObject

PRESENTATION PARTS



50
51
52
# File 'lib/rubypoint/presentation.rb', line 50

def slides
  @slides
end

Instance Method Details

#add_to_relationships(object) ⇒ Object



84
85
86
# File 'lib/rubypoint/presentation.rb', line 84

def add_to_relationships(object)
  self.presentation_rel.add_relationship_for(object)
end

#app_xmlObject



68
69
70
# File 'lib/rubypoint/presentation.rb', line 68

def app_xml
  @app_xml ||= RubyPoint::App.new(self)
end

#clean_file_directoryObject



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

def clean_file_directory
  system("rm -r #{file_directory}")
end

#content_types_xmlObject



72
73
74
# File 'lib/rubypoint/presentation.rb', line 72

def content_types_xml
  @content_types_xml ||= RubyPoint::ContentTypes::XML.new(self)
end

#file_directoryObject



92
93
94
# File 'lib/rubypoint/presentation.rb', line 92

def file_directory
  "#{@working_directory}#{@uuid}"
end

#new_slideObject



76
77
78
# File 'lib/rubypoint/presentation.rb', line 76

def new_slide
  RubyPoint::Slide.new(self)
end

#next_slide_idObject



80
81
82
# File 'lib/rubypoint/presentation.rb', line 80

def next_slide_id
  self.slides.size + 1
end

#open(path) ⇒ Object



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

def open(path)
  system("mkdir #{file_directory}")
  system("cp #{path} #{@working_directory}#{@uuid}/#{@base_file_name}")
  system("unzip -q #{@working_directory}#{@uuid}/#{@base_file_name} -d #{@working_directory}#{@uuid}/")
  system("rm #{@working_directory}#{@uuid}/#{@base_file_name}")
  @files = Dir.glob("#{@working_directory}#{@uuid}/**/*", ::File::FNM_DOTMATCH)
end

#presentation_relObject



60
61
62
# File 'lib/rubypoint/presentation.rb', line 60

def presentation_rel
  @presentation_rel ||= RubyPoint::PresentationRel.new(self)
end

#presentation_xmlObject



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

def presentation_xml
  @presentation_xml ||= RubyPoint::Presentation::Presentation.new(self)
end

#save(file_path, force = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubypoint/presentation.rb', line 30

def save(file_path, force=false)
  slides.each do |s|
    s.write
  end
  presentation_rel.write
  presentation_xml.write
  app_xml.write
  content_types_xml.write
  if ::File.exist?(file_path)
    force ? system("rm -f #{file_path}") : raise("#{file_path} already exists")
  end
  RubyPoint.compress_folder(file_directory, file_path)
end

#slide_directoryObject



88
89
90
# File 'lib/rubypoint/presentation.rb', line 88

def slide_directory
  file_directory + '/ppt/slides'
end

#system(stuff) ⇒ Object



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

def system(stuff)
  puts stuff
  super
end