chupa-text-decomposer-libreoffice 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/Gemfile +34 -0
  4. data/LICENSE.txt +502 -0
  5. data/README.md +45 -0
  6. data/Rakefile +46 -0
  7. data/chupa-text-decomposer-libreoffice.gemspec +51 -0
  8. data/doc/text/news.md +5 -0
  9. data/lib/chupa-text/decomposers/libreoffice.rb +131 -0
  10. data/test/fixture/doc/attributes.doc +0 -0
  11. data/test/fixture/doc/multi-pages.doc +0 -0
  12. data/test/fixture/doc/one-page.doc +0 -0
  13. data/test/fixture/docx/attributes.docx +0 -0
  14. data/test/fixture/docx/multi-pages.docx +0 -0
  15. data/test/fixture/docx/one-page.docx +0 -0
  16. data/test/fixture/odp/attributes.odp +0 -0
  17. data/test/fixture/odp/multi-slides.odp +0 -0
  18. data/test/fixture/odp/one-slide.odp +0 -0
  19. data/test/fixture/ods/attributes.ods +0 -0
  20. data/test/fixture/ods/multi-sheets.ods +0 -0
  21. data/test/fixture/ods/one-sheet.ods +0 -0
  22. data/test/fixture/odt/attributes.odt +0 -0
  23. data/test/fixture/odt/multi-pages.odt +0 -0
  24. data/test/fixture/odt/one-page.odt +0 -0
  25. data/test/fixture/ppt/attributes.ppt +0 -0
  26. data/test/fixture/ppt/multi-slides.ppt +0 -0
  27. data/test/fixture/ppt/one-slide.ppt +0 -0
  28. data/test/fixture/pptx/attributes.pptx +0 -0
  29. data/test/fixture/pptx/multi-slides.pptx +0 -0
  30. data/test/fixture/pptx/one-slide.pptx +0 -0
  31. data/test/fixture/xls/attributes.xls +0 -0
  32. data/test/fixture/xls/multi-sheets.xls +0 -0
  33. data/test/fixture/xls/one-sheet.xls +0 -0
  34. data/test/fixture/xlsx/attributes.xlsx +0 -0
  35. data/test/fixture/xlsx/multi-sheets.xlsx +0 -0
  36. data/test/fixture/xlsx/one-sheet.xlsx +0 -0
  37. data/test/helper.rb +45 -0
  38. data/test/run-test.rb +31 -0
  39. data/test/test-doc.rb +123 -0
  40. data/test/test-docx.rb +123 -0
  41. data/test/test-odp.rb +133 -0
  42. data/test/test-ods.rb +138 -0
  43. data/test/test-odt.rb +123 -0
  44. data/test/test-ppt.rb +133 -0
  45. data/test/test-pptx.rb +136 -0
  46. data/test/test-xls.rb +138 -0
  47. data/test/test-xlsx.rb +138 -0
  48. metadata +187 -0
data/test/test-ppt.rb ADDED
@@ -0,0 +1,133 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require "pathname"
19
+
20
+ class TestPpt < Test::Unit::TestCase
21
+ include FixtureHelper
22
+
23
+ def setup
24
+ setup_decomposer
25
+ end
26
+
27
+ def fixture_path(*components)
28
+ super("ppt", *components)
29
+ end
30
+
31
+ sub_test_case("target?") do
32
+ sub_test_case("extension") do
33
+ def create_data(uri)
34
+ data = ChupaText::Data.new
35
+ data.body = ""
36
+ data.uri = uri
37
+ data
38
+ end
39
+
40
+ def test_ppt
41
+ assert_true(@decomposer.target?(create_data("document.ppt")))
42
+ end
43
+ end
44
+
45
+ sub_test_case("mime-type") do
46
+ def create_data(mime_type)
47
+ data = ChupaText::Data.new
48
+ data.mime_type = mime_type
49
+ data
50
+ end
51
+
52
+ def test_ms_powerpoint
53
+ mime_type = "application/vnd.ms-powerpoint"
54
+ assert_true(@decomposer.target?(create_data(mime_type)))
55
+ end
56
+ end
57
+ end
58
+
59
+ sub_test_case("decompose") do
60
+ include DecomposeHelper
61
+
62
+ sub_test_case("attributes") do
63
+ def test_title
64
+ assert_equal(["Title"], decompose("title"))
65
+ end
66
+
67
+ def test_author
68
+ assert_equal([nil], decompose("author"))
69
+ end
70
+
71
+ def test_subject
72
+ assert_equal(["Subject"], decompose("subject"))
73
+ end
74
+
75
+ def test_keywords
76
+ assert_equal(["Keyword1, Keyword2"], decompose("keywords"))
77
+ end
78
+
79
+ def test_creator
80
+ assert_equal(["Impress"], decompose("creator"))
81
+ end
82
+
83
+ def test_producer
84
+ assert_equal(["LibreOffice 4.1"], decompose("producer"))
85
+ end
86
+
87
+ def test_creation_date
88
+ assert_equal([nil], decompose("creation_date"))
89
+ end
90
+
91
+ private
92
+ def decompose(attribute_name)
93
+ super(fixture_path("attributes.ppt")).collect do |data|
94
+ data[attribute_name]
95
+ end
96
+ end
97
+ end
98
+
99
+ sub_test_case("one slide") do
100
+ def test_body
101
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
102
+ Slide1 title
103
+ Slide1 content
104
+ BODY
105
+ end
106
+
107
+ private
108
+ def decompose
109
+ super(fixture_path("one-slide.ppt"))
110
+ end
111
+ end
112
+
113
+ sub_test_case("multi slides") do
114
+ def test_body
115
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
116
+ Slide1 title
117
+ Slide1 content
118
+ Slide2 title
119
+
120
+ Slide2 content
121
+ Slide3 title
122
+
123
+ Slide3 content
124
+ BODY
125
+ end
126
+
127
+ private
128
+ def decompose
129
+ super(fixture_path("multi-slides.ppt"))
130
+ end
131
+ end
132
+ end
133
+ end
data/test/test-pptx.rb ADDED
@@ -0,0 +1,136 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "pathname"
18
+
19
+ class TestPptx < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("pptx", *components)
28
+ end
29
+
30
+ sub_test_case("target?") do
31
+ sub_test_case("extension") do
32
+ def create_data(uri)
33
+ data = ChupaText::Data.new
34
+ data.body = ""
35
+ data.uri = uri
36
+ data
37
+ end
38
+
39
+ def test_pptx
40
+ assert_true(@decomposer.target?(create_data("document.pptx")))
41
+ end
42
+ end
43
+
44
+ sub_test_case("mime-type") do
45
+ def create_data(mime_type)
46
+ data = ChupaText::Data.new
47
+ data.mime_type = mime_type
48
+ data
49
+ end
50
+
51
+ def test_openxml_presentation
52
+ mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
53
+ assert_true(@decomposer.target?(create_data(mime_type)))
54
+ end
55
+ end
56
+ end
57
+
58
+ sub_test_case("decompose") do
59
+ include DecomposeHelper
60
+
61
+ sub_test_case("attributes") do
62
+ def setup
63
+ super
64
+ omit("We don't have pptx with attributes " +
65
+ "because LibreOffice 4.1 can't generate pptx with attributes.")
66
+ end
67
+
68
+ def test_title
69
+ assert_equal(["Title"], decompose("title"))
70
+ end
71
+
72
+ def test_author
73
+ assert_equal([nil], decompose("author"))
74
+ end
75
+
76
+ def test_subject
77
+ assert_equal(["Subject"], decompose("subject"))
78
+ end
79
+
80
+ def test_keywords
81
+ assert_equal(["Keyword1, Keyword2"], decompose("keywords"))
82
+ end
83
+
84
+ def test_creator
85
+ assert_equal(["Impress"], decompose("creator"))
86
+ end
87
+
88
+ def test_producer
89
+ assert_equal(["LibreOffice 4.1"], decompose("producer"))
90
+ end
91
+
92
+ def test_creation_date
93
+ assert_equal([nil], decompose("creation_date"))
94
+ end
95
+
96
+ private
97
+ def decompose(attribute_name)
98
+ super(fixture_path("attributes.pptx")).collect do |data|
99
+ data[attribute_name]
100
+ end
101
+ end
102
+ end
103
+
104
+ sub_test_case("one slide") do
105
+ def test_body
106
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
107
+ Slide1 title
108
+ Slide1 content
109
+ BODY
110
+ end
111
+
112
+ private
113
+ def decompose
114
+ super(fixture_path("one-slide.pptx"))
115
+ end
116
+ end
117
+
118
+ sub_test_case("multi slides") do
119
+ def test_body
120
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
121
+ Slide1 title
122
+ Slide1 content
123
+ Slide2 title
124
+ Slide2 content
125
+ Slide3 title
126
+ Slide3 content
127
+ BODY
128
+ end
129
+
130
+ private
131
+ def decompose
132
+ super(fixture_path("multi-slides.pptx"))
133
+ end
134
+ end
135
+ end
136
+ end
data/test/test-xls.rb ADDED
@@ -0,0 +1,138 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "pathname"
18
+
19
+ class TestXls < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("xls", *components)
28
+ end
29
+
30
+ sub_test_case("target?") do
31
+ sub_test_case("extension") do
32
+ def create_data(uri)
33
+ data = ChupaText::Data.new
34
+ data.body = ""
35
+ data.uri = uri
36
+ data
37
+ end
38
+
39
+ def test_xls
40
+ assert_true(@decomposer.target?(create_data("document.xls")))
41
+ end
42
+ end
43
+
44
+ sub_test_case("mime-type") do
45
+ def create_data(mime_type)
46
+ data = ChupaText::Data.new
47
+ data.mime_type = mime_type
48
+ data
49
+ end
50
+
51
+ def test_ms_excel
52
+ mime_type = "application/vnd.ms-excel"
53
+ assert_true(@decomposer.target?(create_data(mime_type)))
54
+ end
55
+ end
56
+ end
57
+
58
+ sub_test_case("decompose") do
59
+ include DecomposeHelper
60
+
61
+ sub_test_case("attributes") do
62
+ def test_title
63
+ assert_equal(["Title"], decompose("title"))
64
+ end
65
+
66
+ def test_author
67
+ assert_equal([nil], decompose("author"))
68
+ end
69
+
70
+ def test_subject
71
+ assert_equal(["Subject"], decompose("subject"))
72
+ end
73
+
74
+ def test_keywords
75
+ assert_equal(["Keyword1, Keyword2"], decompose("keywords"))
76
+ end
77
+
78
+ def test_creator
79
+ assert_equal(["Calc"], decompose("creator"))
80
+ end
81
+
82
+ def test_producer
83
+ assert_equal(["LibreOffice 4.1"], decompose("producer"))
84
+ end
85
+
86
+ def test_creation_date
87
+ assert_equal([nil], decompose("creation_date"))
88
+ end
89
+
90
+ private
91
+ def decompose(attribute_name)
92
+ super(fixture_path("attributes.xls")).collect do |data|
93
+ data[attribute_name]
94
+ end
95
+ end
96
+ end
97
+
98
+ sub_test_case("one sheet") do
99
+ def test_body
100
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
101
+ Sheet1 - A1
102
+ Sheet1 - A2
103
+ Sheet1 - B1
104
+ Sheet1 - B2
105
+ BODY
106
+ end
107
+
108
+ private
109
+ def decompose
110
+ super(fixture_path("one-sheet.xls"))
111
+ end
112
+ end
113
+
114
+ sub_test_case("multi sheets") do
115
+ def test_body
116
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
117
+ Sheet1 - A1
118
+ Sheet1 - A2
119
+ Sheet1 - B1
120
+ Sheet1 - B2
121
+ Sheet2 - A1
122
+ Sheet2 - A2
123
+ Sheet2 - B1
124
+ Sheet2 - B2
125
+ Sheet3 - A1
126
+ Sheet3 - A2
127
+ Sheet3 - B1
128
+ Sheet3 - B2
129
+ BODY
130
+ end
131
+
132
+ private
133
+ def decompose
134
+ super(fixture_path("multi-sheets.xls"))
135
+ end
136
+ end
137
+ end
138
+ end
data/test/test-xlsx.rb ADDED
@@ -0,0 +1,138 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "pathname"
18
+
19
+ class TestXlsx < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("xlsx", *components)
28
+ end
29
+
30
+ sub_test_case("target?") do
31
+ sub_test_case("extension") do
32
+ def create_data(uri)
33
+ data = ChupaText::Data.new
34
+ data.body = ""
35
+ data.uri = uri
36
+ data
37
+ end
38
+
39
+ def test_xlsx
40
+ assert_true(@decomposer.target?(create_data("document.xlsx")))
41
+ end
42
+ end
43
+
44
+ sub_test_case("mime-type") do
45
+ def create_data(mime_type)
46
+ data = ChupaText::Data.new
47
+ data.mime_type = mime_type
48
+ data
49
+ end
50
+
51
+ def test_openxml_sheet
52
+ mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
53
+ assert_true(@decomposer.target?(create_data(mime_type)))
54
+ end
55
+ end
56
+ end
57
+
58
+ sub_test_case("decompose") do
59
+ include DecomposeHelper
60
+
61
+ sub_test_case("attributes") do
62
+ def test_title
63
+ assert_equal(["Title"], decompose("title"))
64
+ end
65
+
66
+ def test_author
67
+ assert_equal([nil], decompose("author"))
68
+ end
69
+
70
+ def test_subject
71
+ assert_equal(["Subject"], decompose("subject"))
72
+ end
73
+
74
+ def test_keywords
75
+ assert_equal(["Keyword1, Keyword2"], decompose("keywords"))
76
+ end
77
+
78
+ def test_creator
79
+ assert_equal(["Calc"], decompose("creator"))
80
+ end
81
+
82
+ def test_producer
83
+ assert_equal(["LibreOffice 4.1"], decompose("producer"))
84
+ end
85
+
86
+ def test_creation_date
87
+ assert_equal([nil], decompose("creation_date"))
88
+ end
89
+
90
+ private
91
+ def decompose(attribute_name)
92
+ super(fixture_path("attributes.xlsx")).collect do |data|
93
+ data[attribute_name]
94
+ end
95
+ end
96
+ end
97
+
98
+ sub_test_case("one sheet") do
99
+ def test_body
100
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
101
+ Sheet1 - A1
102
+ Sheet1 - A2
103
+ Sheet1 - B1
104
+ Sheet1 - B2
105
+ BODY
106
+ end
107
+
108
+ private
109
+ def decompose
110
+ super(fixture_path("one-sheet.xlsx"))
111
+ end
112
+ end
113
+
114
+ sub_test_case("multi sheets") do
115
+ def test_body
116
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
117
+ Sheet1 - A1
118
+ Sheet1 - A2
119
+ Sheet1 - B1
120
+ Sheet1 - B2
121
+ Sheet2 - A1
122
+ Sheet2 - A2
123
+ Sheet2 - B1
124
+ Sheet2 - B2
125
+ Sheet3 - A1
126
+ Sheet3 - A2
127
+ Sheet3 - B1
128
+ Sheet3 - B2
129
+ BODY
130
+ end
131
+
132
+ private
133
+ def decompose
134
+ super(fixture_path("multi-sheets.xlsx"))
135
+ end
136
+ end
137
+ end
138
+ end