Class: RTesseract::Command
- Inherits:
-
Object
- Object
- RTesseract::Command
- Defined in:
- lib/rtesseract/command.rb
Constant Summary collapse
- FIXED =
%i[command psm oem lang tessdata_dir user_words user_patterns config_file].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #add_option(*args) ⇒ Object
- #full_command ⇒ Object
-
#initialize(source, output, errors, options) ⇒ Command
constructor
A new instance of Command.
- #other_configs ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(source, output, errors, options) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 13 |
# File 'lib/rtesseract/command.rb', line 7 def initialize(source, output, errors, ) @source = source @output = output @options = @errors = errors @full_command = [.command, @source, @output] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rtesseract/command.rb', line 5 def @options end |
Instance Method Details
#add_option(*args) ⇒ Object
30 31 32 33 34 |
# File 'lib/rtesseract/command.rb', line 30 def add_option(*args) return unless args.last @full_command << args.map(&:to_s) end |
#full_command ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rtesseract/command.rb', line 15 def full_command add_option('--psm', .psm) add_option('--oem', .oem) add_option('-l', .lang) add_option('--tessdata_dir', .tessdata_dir) add_option('--user_words', .user_words) add_option('--user_patterns', .user_patterns) other_configs add_option(.config_file) @full_command end |
#other_configs ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rtesseract/command.rb', line 36 def other_configs @options.to_h.map do |key, value| next if FIXED.include?(key) add_option('-c', "#{key}=#{value}") end end |
#run ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/rtesseract/command.rb', line 44 def run output, error, status = Open3.capture3(*full_command.flatten) @errors.push(error) return output if status.success? raise RTesseract::Error, error end |