chupa-text-decomposer-libreoffice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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-docx.rb ADDED
@@ -0,0 +1,123 @@
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 TestDocx < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("docx", *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_docx
40
+ assert_true(@decomposer.target?(create_data("document.docx")))
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_document
52
+ mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
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(["Writer"], 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.docx")).collect do |data|
93
+ data[attribute_name]
94
+ end
95
+ end
96
+ end
97
+
98
+ sub_test_case("one page") do
99
+ def test_body
100
+ assert_equal(["Page1"], decompose.collect(&:body))
101
+ end
102
+
103
+ private
104
+ def decompose
105
+ super(fixture_path("one-page.docx"))
106
+ end
107
+ end
108
+
109
+ sub_test_case("multi pages") do
110
+ def test_body
111
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
112
+ Page1
113
+ Page2
114
+ BODY
115
+ end
116
+
117
+ private
118
+ def decompose
119
+ super(fixture_path("multi-pages.docx"))
120
+ end
121
+ end
122
+ end
123
+ end
data/test/test-odp.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 TestOdp < Test::Unit::TestCase
21
+ include FixtureHelper
22
+
23
+ def setup
24
+ setup_decomposer
25
+ end
26
+
27
+ def fixture_path(*components)
28
+ super("odp", *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_odp
41
+ assert_true(@decomposer.target?(create_data("document.odp")))
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_opendocument_presentation
53
+ mime_type = "application/vnd.oasis.opendocument.presentation"
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.odp")).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.odp"))
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.odp"))
130
+ end
131
+ end
132
+ end
133
+ end
data/test/test-ods.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 TestOds < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("ods", *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_ods
40
+ assert_true(@decomposer.target?(create_data("document.ods")))
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_opendocument_spareadsheet
52
+ mime_type = "application/vnd.oasis.opendocument.spreadsheet"
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.ods")).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.ods"))
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.ods"))
135
+ end
136
+ end
137
+ end
138
+ end
data/test/test-odt.rb ADDED
@@ -0,0 +1,123 @@
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 TestOdt < Test::Unit::TestCase
20
+ include FixtureHelper
21
+
22
+ def setup
23
+ setup_decomposer
24
+ end
25
+
26
+ def fixture_path(*components)
27
+ super("odt", *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_odt
40
+ assert_true(@decomposer.target?(create_data("document.odt")))
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_opendocument_text
52
+ mime_type = "application/vnd.oasis.opendocument.text"
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(["Writer"], 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.odt")).collect do |data|
93
+ data[attribute_name]
94
+ end
95
+ end
96
+ end
97
+
98
+ sub_test_case("one page") do
99
+ def test_body
100
+ assert_equal(["Page1"], decompose.collect(&:body))
101
+ end
102
+
103
+ private
104
+ def decompose
105
+ super(fixture_path("one-page.odt"))
106
+ end
107
+ end
108
+
109
+ sub_test_case("multi pages") do
110
+ def test_body
111
+ assert_equal([<<-BODY.chomp], decompose.collect(&:body))
112
+ Page1
113
+ Page2
114
+ BODY
115
+ end
116
+
117
+ private
118
+ def decompose
119
+ super(fixture_path("multi-pages.odt"))
120
+ end
121
+ end
122
+ end
123
+ end