-
Notifications
You must be signed in to change notification settings - Fork 4
/
dependency_checker.rb
40 lines (34 loc) · 1.03 KB
/
dependency_checker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Tesseract
class DependencyChecker
#putting these here so its easyer to test
IMAGE_MAGICK_ERROR = "ImageMagick \"convert\" command not found! Make sure ImageMagick is installed and in the system path"
TESSERACT_ERROR = "\"tesseract\" command not found! Make sure tesseract is installed and in the system path"
OS_ERROR = "Only Unix Based enviroments are supported Mac, Linux, etc."
def self.check!
check_os!
check_for_tesseract!
check_for_imagemagick!
true
end
private
#for easy mocking
def self.run_cmd(cmd)
`#{cmd}`
end
def self.check_os!
case ::RUBY_PLATFORM
when /darwin/
return true
when /linux/, /unix/
return true
end
raise Exception, OS_ERROR
end
def self.check_for_imagemagick!
raise Exception, IMAGE_MAGICK_ERROR if run_cmd('which convert').empty?
end
def self.check_for_tesseract!
raise Exception, TESSERACT_ERROR if run_cmd('which tesseract').empty?
end
end
end