Class: RubyPowerpoint::Slide

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_powerpoint/slide.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presentation, slide_xml_path) ⇒ Slide

Returns a new instance of Slide.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_powerpoint/slide.rb', line 12

def initialize presentation, slide_xml_path
  @presentation = presentation
  @slide_xml_path = slide_xml_path
  @slide_number = extract_slide_number_from_path slide_xml_path
  @slide_notes_xml_path = "ppt/notesSlides/notesSlide#{@slide_number}.xml"
  @slide_file_name = extract_slide_file_name_from_path slide_xml_path

  parse_slide
  parse_slide_notes
  parse_relation
end

Instance Attribute Details

#presentationObject (readonly)

Returns the value of attribute presentation.



7
8
9
# File 'lib/ruby_powerpoint/slide.rb', line 7

def presentation
  @presentation
end

#slide_file_nameObject (readonly)

Returns the value of attribute slide_file_name.



7
8
9
# File 'lib/ruby_powerpoint/slide.rb', line 7

def slide_file_name
  @slide_file_name
end

#slide_numberObject (readonly)

Returns the value of attribute slide_number.



7
8
9
# File 'lib/ruby_powerpoint/slide.rb', line 7

def slide_number
  @slide_number
end

Instance Method Details

#contentObject



42
43
44
# File 'lib/ruby_powerpoint/slide.rb', line 42

def content
  content_elements @slide_xml
end

#imagesObject



55
56
57
58
59
60
61
# File 'lib/ruby_powerpoint/slide.rb', line 55

def images
  image_elements(@relation_xml)
    .map.each do |node|
      @presentation.files.file.open(
        node['Target'].gsub('..', 'ppt'))
    end
end

#notes_contentObject



46
47
48
# File 'lib/ruby_powerpoint/slide.rb', line 46

def notes_content
  content_elements @slide_notes_xml
end

#paragraphsObject



67
68
69
# File 'lib/ruby_powerpoint/slide.rb', line 67

def paragraphs
  paragraph_element @slide_xml
end

#parse_relationObject



34
35
36
37
38
39
40
# File 'lib/ruby_powerpoint/slide.rb', line 34

def parse_relation
  @relation_xml_path = "ppt/slides/_rels/#{@slide_file_name}.rels"
  if @presentation.files.file.exist? @relation_xml_path
    relation_doc = @presentation.files.file.open @relation_xml_path
    @relation_xml = Nokogiri::XML::Document.parse relation_doc
  end
end

#parse_slideObject



24
25
26
27
# File 'lib/ruby_powerpoint/slide.rb', line 24

def parse_slide
  slide_doc = @presentation.files.file.open @slide_xml_path
  @slide_xml = Nokogiri::XML::Document.parse slide_doc
end

#parse_slide_notesObject



29
30
31
32
# File 'lib/ruby_powerpoint/slide.rb', line 29

def parse_slide_notes
  slide_notes_doc = @presentation.files.file.open @slide_notes_xml_path rescue nil
  @slide_notes_xml = Nokogiri::XML::Document.parse(slide_notes_doc) if slide_notes_doc
end

#slide_numObject



63
64
65
# File 'lib/ruby_powerpoint/slide.rb', line 63

def slide_num
  @slide_xml_path.match(/slide([0-9]*)\.xml$/)[1].to_i
end

#titleObject



50
51
52
53
# File 'lib/ruby_powerpoint/slide.rb', line 50

def title
  title_elements = title_elements(@slide_xml)
  title_elements.join(" ") if title_elements.length > 0
end