ruby_powerpoint 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4af53e4c22fe4a2b59600737efc078741f014de
4
+ data.tar.gz: 1175183988e0224d6409cdbc9dc944a2885a21b2
5
+ SHA512:
6
+ metadata.gz: a896c0b5b334e38f1d68d47c5e1efadff04586840d25c5f5931c8eea3c3cced231c919d6a2e8da8ebda76a456a345a6dcd026f38493aafdb33a2a69cc78b1faf
7
+ data.tar.gz: 30d71c88a38310e000fcb21d7098f729d44c36e30b71e6a9b89de1e8f19aa354412ca73be3850c4c41ba7995ffa744944c19155d9afbef64f2dacd1cd9dd2629
@@ -2,7 +2,6 @@ require "ruby_powerpoint/version"
2
2
  require 'ruby_powerpoint/presentation'
3
3
  require 'ruby_powerpoint/slide'
4
4
 
5
-
6
5
  module RubyPowerpoint
7
6
  # Your code goes here...
8
7
  end
@@ -14,7 +14,7 @@ module RubyPowerpoint
14
14
 
15
15
  def slides
16
16
  slides = Array.new
17
- @files.each_with_index do |doc, i|
17
+ @files.sort{|a,b| a.name <=> b.name}.each_with_index do |doc, i|
18
18
  if doc.name.include? 'ppt/slides/slide'
19
19
  slides.push RubyPowerpoint::Slide.new(self, doc.name, i)
20
20
  end
@@ -6,7 +6,7 @@ module RubyPowerpoint
6
6
 
7
7
  attr_reader :presentation,
8
8
  :path,
9
- :ndex
9
+ :index
10
10
 
11
11
  def initialize presentation, path, index
12
12
  @presentation = presentation
@@ -23,5 +23,29 @@ module RubyPowerpoint
23
23
  end
24
24
  content
25
25
  end
26
+
27
+ def title
28
+ #extracts just the title from the slide. Useful information on how to find just the title shape using C# is found here: http://msdn.microsoft.com/en-us/library/office/cc850843.aspx but you'll obviously need to dig into the XML structure if you aren't using C#, so see http://msdn.microsoft.com/en-us/library/office/gg278332(v=office.15).aspx
29
+ # should return nil if there is no title
30
+ title_elements = Array.new
31
+ doc = @presentation.files.file.open @path
32
+ xml = Nokogiri::XML::Document.parse doc
33
+ title_elements(xml).join(" ") if title_elements(xml).length > 0
34
+ end
35
+
36
+ protected
37
+
38
+ def title_elements(xml)
39
+ shape_elements(xml).select{|shape| element_is_title(shape)}
40
+ end
41
+
42
+ def shape_elements(xml)
43
+ xml.xpath('//p:sp')
44
+ end
45
+
46
+ def element_is_title(shape)
47
+ shape.xpath('.//p:nvSpPr/p:nvPr/p:ph').select{|prop| prop['type'] == 'title' || prop['type'] == 'ctrTitle'}.length > 0
48
+ end
49
+
26
50
  end
27
51
  end
@@ -1,3 +1,3 @@
1
1
  module RubyPowerpoint
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
Binary file
data/spec/test_spec.rb CHANGED
@@ -22,3 +22,50 @@ describe 'RubyPowerpoint parsing a sample PPTX file' do
22
22
  @deck.slides.last.content.should eql ["WTF?", "What the hell s gong on?", "1234", "asdf", "34", "6"]
23
23
  end
24
24
  end
25
+
26
+ describe 'open rime.pptx file' do
27
+ # I couldn't get the sample.pptx file to open on either Powerpoint 2007 on Windows 7 or in Powerpoint 2008 on Mac OS X 10.9, so I created my own file to test
28
+ before(:all) do
29
+ @deck = RubyPowerpoint::Presentation.new 'spec/fixtures/rime.pptx'
30
+ end
31
+
32
+ after(:all) do
33
+ @deck.close
34
+ end
35
+
36
+ it 'opened rime.pptx successfully' do
37
+ @deck.should_not be_nil
38
+ @deck.slides.should_not eql []
39
+ end
40
+
41
+ it 'should have the right number of slides' do
42
+ @deck.slides.length.should eql 9
43
+ end
44
+
45
+ it 'the old content method should work the same way' do
46
+ @deck.slides[0].content.should eql ["The Rime of the Ancient Mariner", "(text of 1834)", "http://rpo.library.utoronto.ca/poems/rime-ancient-mariner-text-1834"]
47
+ end
48
+
49
+ context 'the titles should be right' do
50
+ it 'should be able to get a main slide (usually centered)' do
51
+ @deck.slides[0].title.should eql "The Rime of the Ancient Mariner"
52
+ end
53
+ it 'should be able to get regular slide titles' do
54
+ @deck.slides[1].title.should eql "Argument"
55
+ @deck.slides[2].title.should eql "PART I"
56
+ @deck.slides[3].title.should eql "PART II"
57
+ @deck.slides[4].title.should eql "Part III"
58
+ @deck.slides[8].title.should eql "There's more"
59
+ end
60
+ it 'should return nil if the slide has no title' do
61
+ @deck.slides[5].title.should be_nil
62
+ @deck.slides[6].title.should be_nil
63
+ end
64
+
65
+ it 'should only get one title even if there are two things that visually look like titles' do
66
+ @deck.slides[7].title.should eql "What if we have two"
67
+ end
68
+ end
69
+
70
+
71
+ end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_powerpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - pythonicrubyist
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 2.13.0
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 2.13.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: nokogiri
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: 1.6.0
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: 1.6.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rubyzip
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: 0.9.9
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: 0.9.9
94
83
  description: A Ruby gem that can extract text from PowerPoint(pptx) files.
@@ -98,7 +87,7 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
90
+ - ".gitignore"
102
91
  - Gemfile
103
92
  - LICENSE.txt
104
93
  - README.rdoc
@@ -110,35 +99,36 @@ files:
110
99
  - ruby_powerpoint.gemspec
111
100
  - spec/fixtures/.~lock.sample.pptx#
112
101
  - spec/fixtures/invalid.xls
102
+ - spec/fixtures/rime.pptx
113
103
  - spec/fixtures/sample.pptx
114
104
  - spec/test_spec.rb
115
105
  homepage: https://github.com/pythonicrubyist/ruby_powerpoint
116
106
  licenses:
117
107
  - MIT
108
+ metadata: {}
118
109
  post_install_message:
119
110
  rdoc_options: []
120
111
  require_paths:
121
112
  - lib
122
113
  required_ruby_version: !ruby/object:Gem::Requirement
123
- none: false
124
114
  requirements:
125
- - - ! '>='
115
+ - - ">="
126
116
  - !ruby/object:Gem::Version
127
117
  version: 1.9.2
128
118
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
119
  requirements:
131
- - - ! '>='
120
+ - - ">="
132
121
  - !ruby/object:Gem::Version
133
122
  version: '0'
134
123
  requirements: []
135
124
  rubyforge_project:
136
- rubygems_version: 1.8.25
125
+ rubygems_version: 2.2.0.rc.1
137
126
  signing_key:
138
- specification_version: 3
127
+ specification_version: 4
139
128
  summary: A Ruby gem for Parsng text from PowerPoint(pptx) files.
140
129
  test_files:
141
130
  - spec/fixtures/.~lock.sample.pptx#
142
131
  - spec/fixtures/invalid.xls
132
+ - spec/fixtures/rime.pptx
143
133
  - spec/fixtures/sample.pptx
144
134
  - spec/test_spec.rb