summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authormarc <[email protected]>2015-07-03 16:58:21 +0200
committermarc <[email protected]>2015-07-03 16:58:21 +0200
commitd7de10ade8d8f28efd0a41963aa263f9ef58ceb4 (patch)
tree8677c3ea89677f395059eef8fd67505d9a792557 /lib
parentc7c7937dcde9a94f2e5ee0549451b34e410803e0 (diff)
downloadcaxlsx-d7de10ade8d8f28efd0a41963aa263f9ef58ceb4.tar.gz
caxlsx-d7de10ade8d8f28efd0a41963aa263f9ef58ceb4.zip
Extract mime type detection to an utility class
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx.rb1
-rw-r--r--lib/axlsx/drawing/pic.rb2
-rw-r--r--lib/axlsx/util/mime_type_utils.rb11
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 14456024..c5d26c2b 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -12,6 +12,7 @@ require 'axlsx/util/options_parser'
# to be included with parsable intitites.
#require 'axlsx/util/parser.rb'
require 'axlsx/util/string'
+require 'axlsx/util/mime_type_utils'
require 'axlsx/stylesheet/styles.rb'
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index b090c661..a1e8483a 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -67,7 +67,7 @@ module Axlsx
def image_src=(v)
Axlsx::validate_string(v)
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeMagic.by_magic(File.open(v)).to_s
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
raise ArgumentError, "File does not exist" unless File.exist?(v)
@image_src = v
end
diff --git a/lib/axlsx/util/mime_type_utils.rb b/lib/axlsx/util/mime_type_utils.rb
new file mode 100644
index 00000000..3fe2dbbd
--- /dev/null
+++ b/lib/axlsx/util/mime_type_utils.rb
@@ -0,0 +1,11 @@
+module Axlsx
+ # This module defines some utils related with mime type detection
+ module MimeTypeUtils
+ # Detect a file mime type
+ # @param [String] v File path
+ # @return [String] File mime type
+ def self.get_mime_type(v)
+ MimeMagic.by_magic(File.open(v)).to_s
+ end
+ end
+end