poleica 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +15 -0
  4. data/CHANGELOG.md +16 -0
  5. data/Gemfile +19 -0
  6. data/Gemfile.lock +192 -0
  7. data/Guardfile +19 -0
  8. data/LICENSE +20 -0
  9. data/README.md +82 -0
  10. data/Rakefile +7 -0
  11. data/lib/poleica/converters/coercive.rb +68 -0
  12. data/lib/poleica/converters/convertible.rb +60 -0
  13. data/lib/poleica/converters/general.rb +18 -0
  14. data/lib/poleica/converters/graphics_magick.rb +110 -0
  15. data/lib/poleica/converters/libre_office.rb +103 -0
  16. data/lib/poleica/converters/null.rb +17 -0
  17. data/lib/poleica/converters/utils.rb +49 -0
  18. data/lib/poleica/pathable.rb +20 -0
  19. data/lib/poleica/polei.rb +24 -0
  20. data/lib/poleica/types/archive.rb +12 -0
  21. data/lib/poleica/types/document.rb +53 -0
  22. data/lib/poleica/types/image.rb +37 -0
  23. data/lib/poleica/types/null.rb +12 -0
  24. data/lib/poleica/types/pdf.rb +19 -0
  25. data/lib/poleica/types/typeable.rb +50 -0
  26. data/lib/poleica/version.rb +4 -0
  27. data/lib/poleica.rb +27 -0
  28. data/poleica.gemspec +18 -0
  29. data/test/poleica/converters/coercive_test.rb +77 -0
  30. data/test/poleica/converters/convertible_test.rb +44 -0
  31. data/test/poleica/converters/general_test.rb +11 -0
  32. data/test/poleica/converters/graphics_magick_test.rb +102 -0
  33. data/test/poleica/converters/libre_office_test.rb +55 -0
  34. data/test/poleica/converters/null_test.rb +18 -0
  35. data/test/poleica/converters/utils_test.rb +5 -0
  36. data/test/poleica/pathable_test.rb +11 -0
  37. data/test/poleica/polei_test.rb +15 -0
  38. data/test/poleica/types/typeable_test.rb +57 -0
  39. data/test/poleica_test.rb +10 -0
  40. data/test/support/files/1px.gif +0 -0
  41. data/test/support/files/example.doc +0 -0
  42. data/test/support/files/example.mp3 +0 -0
  43. data/test/support/files/example.pdf +0 -0
  44. data/test/support/files/example.png +0 -0
  45. data/test/test_helper.rb +38 -0
  46. metadata +134 -0
@@ -0,0 +1,102 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the GraphicsMagick Converter Module
4
+ class GraphicsMagickTest < Minitest::Test
5
+
6
+ PDF_PATH = "#{Support.support_path}/files/example.pdf"
7
+
8
+ def setup
9
+ clean_png_file
10
+ end
11
+
12
+ def test_to_png_returned_path
13
+ returned_path = pdf_polei.to_png
14
+ expected_path = Support.expected_converted_path(PDF_PATH, :png)
15
+ assert_equal(expected_path, returned_path)
16
+ clean_png_file
17
+ end
18
+
19
+ def test_to_png_create_a_file
20
+ returned_path = pdf_polei.to_png
21
+ assert(returned_path && File.exists?(returned_path))
22
+ clean_png_file
23
+ end
24
+
25
+ def test_to_png_path_option
26
+ path_option = "#{Support.support_path}/files/path_test.png"
27
+ returned_path = pdf_polei.to_png(path: path_option)
28
+ assert(returned_path)
29
+ assert(File.exists?(path_option))
30
+ assert(File.exists?(returned_path))
31
+ assert_equal(returned_path, path_option)
32
+ File.delete(path_option) if File.exists?(path_option)
33
+ end
34
+
35
+ def test_to_png_path_with_spaces
36
+ path_option = "#{Support.support_path}/files/path with spaces.png"
37
+ returned_path = pdf_polei.to_png(path: path_option)
38
+ assert(returned_path)
39
+ assert(File.exists?(path_option))
40
+ assert(File.exists?(returned_path))
41
+ assert_equal(returned_path, path_option)
42
+ File.delete(path_option) if File.exists?(path_option)
43
+ end
44
+
45
+ def test_path_folder
46
+ path_option = '/tmp/'
47
+ expected_path = "/tmp/#{File.basename(pdf_polei.path_with_md5)}"
48
+ returned_path = pdf_polei.to_png(path: path_option)
49
+ assert(returned_path)
50
+ assert(File.exists?(expected_path))
51
+ assert(File.exists?(returned_path))
52
+ assert_equal(expected_path, returned_path)
53
+ File.delete(expected_path) if File.exists?(expected_path)
54
+ end
55
+
56
+ def test_force_resize_option
57
+ returned_path = pdf_polei.to_png(width: 100,
58
+ height: 100,
59
+ force_resize: true)
60
+ expected_path = Support.expected_converted_path(PDF_PATH, :png)
61
+ bin_path = Poleica::Converters::GraphicsMagick.new(pdf_polei).bin_path
62
+ assert_equal(expected_path, returned_path)
63
+ size = `#{bin_path} identify #{returned_path}`.split[2][/(\w)*/]
64
+ assert_equal('100x100', size)
65
+ clean_png_file
66
+ end
67
+
68
+ def test_resize_option
69
+ returned_path = pdf_polei.to_png(width: 100,
70
+ height: 100)
71
+ expected_path = Support.expected_converted_path(PDF_PATH, :png)
72
+ bin_path = Poleica::Converters::GraphicsMagick.new(pdf_polei).bin_path
73
+ assert_equal(expected_path, returned_path)
74
+ size = `#{bin_path} identify #{returned_path}`.split[2][/(\w)*/]
75
+ assert_equal('77x100', size)
76
+ clean_png_file
77
+ end
78
+
79
+ def test_thumbnail_option
80
+ returned_path = pdf_polei.to_png(width: 100,
81
+ height: 100,
82
+ thumbnail: true)
83
+ expected_path = Support.expected_converted_path(PDF_PATH, :png)
84
+ bin_path = Poleica::Converters::GraphicsMagick.new(pdf_polei).bin_path
85
+ assert_equal(expected_path, returned_path)
86
+ size = `#{bin_path} identify #{returned_path}`.split[2][/(\w)*/]
87
+ assert_equal('100x100', size)
88
+ clean_png_file
89
+ end
90
+
91
+ private
92
+
93
+ def clean_png_file
94
+ if File.exists?(Support.expected_converted_path(PDF_PATH, :png))
95
+ File.delete(Support.expected_converted_path(PDF_PATH, :png))
96
+ end
97
+ end
98
+
99
+ def pdf_polei
100
+ Poleica::Polei.new("#{Support.support_path}/files/example.pdf")
101
+ end
102
+ end # class GraphicsMagickTest
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the LibreOffice Converter Module
4
+ class LibreOfficeTest < Minitest::Test
5
+
6
+ DOC_PATH = "#{Support.support_path}/files/example.doc"
7
+
8
+ def setup
9
+ clean_pdf_file
10
+ end
11
+
12
+ def test_to_pdf_returned_path
13
+ returned_path = doc_polei.to_pdf
14
+ expected_path = Support.expected_converted_path(DOC_PATH, :pdf)
15
+ assert_equal(expected_path, returned_path)
16
+ clean_pdf_file
17
+ end
18
+
19
+ def test_to_pdf_create_a_file
20
+ returned_path = doc_polei.to_pdf
21
+ assert(returned_path && File.exists?(returned_path))
22
+ clean_pdf_file
23
+ end
24
+
25
+ def test_path_option
26
+ path_option = "#{Support.support_path}/files/path_test.pdf"
27
+ returned_path = doc_polei.to_pdf(path: path_option)
28
+ assert(returned_path)
29
+ assert(File.exists?(path_option))
30
+ assert(File.exists?(returned_path))
31
+ assert_equal(returned_path, path_option)
32
+ File.delete(path_option) if File.exists?(path_option)
33
+ end
34
+
35
+ def test_path_folder
36
+ path_option = '/tmp/'
37
+ returned_path = doc_polei.to_pdf(path: path_option)
38
+ assert(returned_path)
39
+ assert(File.exists?(path_option))
40
+ assert(File.exists?(returned_path))
41
+ assert_equal(returned_path, path_option)
42
+ end
43
+
44
+ private
45
+
46
+ def clean_pdf_file
47
+ if File.exists?(Support.expected_converted_path(DOC_PATH, :pdf))
48
+ File.delete(Support.expected_converted_path(DOC_PATH, :pdf))
49
+ end
50
+ end
51
+
52
+ def doc_polei
53
+ Poleica::Polei.new("#{Support.support_path}/files/example.doc")
54
+ end
55
+ end # class LibreOfficeTest
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Null Converter Module
4
+ class NullTest < Minitest::Test
5
+ def test_it_returns_nil_on_to_method
6
+ method_name = :to_random
7
+ file = Minitest::Mock.new
8
+ converter = Poleica::Converters::Null.new(file)
9
+ assert_nil(converter.send(method_name))
10
+ end
11
+
12
+ def test_it_raise_no_method_error_on_other_calls
13
+ method_name = :random
14
+ file = Minitest::Mock.new
15
+ converter = Poleica::Converters::Null.new(file)
16
+ assert_raises(NoMethodError) { converter.send(method_name) }
17
+ end
18
+ end # class NullTest
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Utils Converter Module
4
+ class UtilsTest < Minitest::Test
5
+ end
@@ -0,0 +1,11 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Pathable Module
4
+ class PathableTest < Minitest::Test
5
+ def test_path_for_extension
6
+ mp3_path = "#{Support.support_path}/files/example.mp3"
7
+ mp3_polei = Poleica::Polei.new(mp3_path)
8
+ expected_path = "#{Support.support_path}/files/example.png"
9
+ assert_equal(expected_path, mp3_polei.send(:path_for_extension, :png))
10
+ end
11
+ end # class PathableTest
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Polei Class
4
+ class PoleiTest < Minitest::Test
5
+ def test_it_returns_name
6
+ polei = Poleica::Polei.new("#{Support.support_path}/files/example.mp3")
7
+ assert_equal('example', polei.name)
8
+ end
9
+
10
+ def test_it_returns_path
11
+ file_path = "#{Support.support_path}/files/example.mp3"
12
+ polei = Poleica::Polei.new(file_path)
13
+ assert_equal(file_path, polei.path)
14
+ end
15
+ end # class PoleiTest
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Typeable Module
4
+ class TypeableTest < Minitest::Test
5
+ EXTENSION_NAMES ||= %w{doc pdf mp3 png}
6
+
7
+ def test_that_it_extracts_a_mimetype
8
+ expected_mime_types = %w{
9
+ application/pdf
10
+ audio/mpeg
11
+ image/png
12
+ }
13
+ mime_types = files_enumerator.map(&:file_mimetype)
14
+ # Don't test doc files, it doesnt behave the same way
15
+ # on Linux or MacOS (maybe FIXME)
16
+ mime_types.shift
17
+ assert_equal(expected_mime_types, mime_types)
18
+ end
19
+
20
+ def test_that_it_extracts_an_extension
21
+ expected_extensions = extension_names
22
+ extensions = files_enumerator.map(&:file_extension)
23
+ assert_equal(expected_extensions, extensions)
24
+ end
25
+
26
+ def test_that_it_extracts_a_type_object
27
+ expected_classes = [
28
+ Poleica::Types::Document,
29
+ Poleica::Types::Null,
30
+ Poleica::Types::Document,
31
+ Poleica::Types::Image
32
+ ]
33
+ classes = files_enumerator.map do |type_detector|
34
+ type_detector.file_type.class
35
+ end
36
+ assert(expected_classes, classes)
37
+ end
38
+
39
+ def test_that_it_returns_null_type_by_default
40
+ mp3_path = "#{Support.support_path}/files/example.mp3"
41
+ type_class = Poleica::Polei.new(mp3_path).file_type.class
42
+ assert_equal(type_class, Poleica::Types::Null)
43
+ end
44
+
45
+ ## Helpers
46
+
47
+ def files_enumerator
48
+ extension_names.map do |extension|
49
+ file_path = "#{Support.support_path}/files/example.#{extension}"
50
+ Poleica::Polei.new(file_path)
51
+ end.to_enum
52
+ end
53
+
54
+ def extension_names
55
+ EXTENSION_NAMES
56
+ end
57
+ end # class TypeableTest
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Poleica Module
4
+ class PoleicaTest < Minitest::Test
5
+ def test_duck_type_path
6
+ obj = Struct.new(:path).new("#{Support.support_path}/files/example.mp3")
7
+ polei = Poleica.new(obj)
8
+ assert_equal("#{Support.support_path}/files/example.mp3", polei.path)
9
+ end
10
+ end # class PoleicaTest
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ if ENV['COVERAGE'] || ENV['TRAVIS']
3
+ require 'coveralls'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ Coveralls.wear!
11
+ end
12
+
13
+ gem 'minitest'
14
+ require 'minitest/autorun'
15
+ require 'poleica'
16
+
17
+ # The Support Module contains support methods for the tests
18
+ module Support
19
+ module_function
20
+ def support_path
21
+ @support_path ||= File.expand_path('../support', __FILE__)
22
+ end
23
+
24
+ def path_without_extension(path)
25
+ File.join(File.dirname(path), File.basename(path, '.*'))
26
+ end
27
+
28
+ def expected_converted_path(
29
+ original_file_path = "#{Support.support_path}/files/example.pdf",
30
+ converted_extension = :png
31
+ )
32
+ data = File.read(original_file_path)
33
+ md5 = Digest::MD5.new
34
+ digest = md5.hexdigest(data)
35
+ path_without_extension(original_file_path) +
36
+ "-#{digest}.#{converted_extension}"
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poleica
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.6
5
+ platform: ruby
6
+ authors:
7
+ - Antoine Lyset
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '1.3'
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.3'
24
+ type: :development
25
+ prerelease: false
26
+ name: bundler
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ version_requirements: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ name: rake
41
+ description: Poleica can convert docs and images to PDF and PNG, it can be extended
42
+ to handle a lot of converters
43
+ email: antoinelyset@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - Guardfile
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/poleica.rb
58
+ - lib/poleica/converters/coercive.rb
59
+ - lib/poleica/converters/convertible.rb
60
+ - lib/poleica/converters/general.rb
61
+ - lib/poleica/converters/graphics_magick.rb
62
+ - lib/poleica/converters/libre_office.rb
63
+ - lib/poleica/converters/null.rb
64
+ - lib/poleica/converters/utils.rb
65
+ - lib/poleica/pathable.rb
66
+ - lib/poleica/polei.rb
67
+ - lib/poleica/types/archive.rb
68
+ - lib/poleica/types/document.rb
69
+ - lib/poleica/types/image.rb
70
+ - lib/poleica/types/null.rb
71
+ - lib/poleica/types/pdf.rb
72
+ - lib/poleica/types/typeable.rb
73
+ - lib/poleica/version.rb
74
+ - poleica.gemspec
75
+ - test/poleica/converters/coercive_test.rb
76
+ - test/poleica/converters/convertible_test.rb
77
+ - test/poleica/converters/general_test.rb
78
+ - test/poleica/converters/graphics_magick_test.rb
79
+ - test/poleica/converters/libre_office_test.rb
80
+ - test/poleica/converters/null_test.rb
81
+ - test/poleica/converters/utils_test.rb
82
+ - test/poleica/pathable_test.rb
83
+ - test/poleica/polei_test.rb
84
+ - test/poleica/types/typeable_test.rb
85
+ - test/poleica_test.rb
86
+ - test/support/files/1px.gif
87
+ - test/support/files/example.doc
88
+ - test/support/files/example.mp3
89
+ - test/support/files/example.pdf
90
+ - test/support/files/example.png
91
+ - test/test_helper.rb
92
+ homepage: https://github.com/antoinelyset/poleica
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.0
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A general converter and thumbnail creator
116
+ test_files:
117
+ - test/poleica/converters/coercive_test.rb
118
+ - test/poleica/converters/convertible_test.rb
119
+ - test/poleica/converters/general_test.rb
120
+ - test/poleica/converters/graphics_magick_test.rb
121
+ - test/poleica/converters/libre_office_test.rb
122
+ - test/poleica/converters/null_test.rb
123
+ - test/poleica/converters/utils_test.rb
124
+ - test/poleica/pathable_test.rb
125
+ - test/poleica/polei_test.rb
126
+ - test/poleica/types/typeable_test.rb
127
+ - test/poleica_test.rb
128
+ - test/support/files/1px.gif
129
+ - test/support/files/example.doc
130
+ - test/support/files/example.mp3
131
+ - test/support/files/example.pdf
132
+ - test/support/files/example.png
133
+ - test/test_helper.rb
134
+ has_rdoc: