Sha256: edccf015617c5453423a938dbdaae2e61391fe5da3eeab82565d87d93eafc409

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'tmpdir'

class RTesseract
  class Command
    FIXED = [:command, :psm, :oem, :lang, :tessdata_dir, :user_words, :user_patterns, :config_file]

    attr_reader :options

    def initialize(source, output, options)
      @source = source
      @output = output
      @options = options
    end

    def configs
      @options.to_h.map { |key, value| ['-c', "#{key}=#{value}"] unless FIXED.include?(key) }.compact
    end

    def full_command
      command = [options.command, @source, @output]

      command << ['--psm', options.psm.to_s] if options.psm
      command << ['--oem', options.oem.to_s] if options.oem
      command << ['-l', options.lang] if options.lang

      command << ['--tessdata_dir', options.tessdata_dir] if options.tessdata_dir
      command << ['--user_words', options.user_words] if options.user_words
      command << ['--user_patterns', options.user_patterns] if options.user_patterns

      command << configs

      command << options.config_file.to_s if options.config_file

      command.flatten
    end

    def run
      Open3.capture2e(*full_command)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rtesseract-3.0.0 lib/rtesseract/command.rb