Class: RTesseract::Mixed

Inherits:
Object
  • Object
show all
Defined in:
lib/rtesseract/mixed.rb

Instance Method Summary collapse

Constructor Details

#initialize(src = "", options = {}) {|_self| ... } ⇒ Mixed

Returns a new instance of Mixed.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
7
8
9
# File 'lib/rtesseract/mixed.rb', line 3

def initialize(src="", options={})
  @source  = Pathname.new src
  @options = options
  @value   = ""
  @areas = options.delete(:areas) || []
  yield self if block_given?
end

Instance Method Details

#area(x, y, width, height) ⇒ Object



11
12
13
14
# File 'lib/rtesseract/mixed.rb', line 11

def area(x, y, width, height)
  @value = ""
  @areas << {:x => x,  :y => y, :width => width, :height => height}
end

#areasObject



16
17
18
# File 'lib/rtesseract/mixed.rb', line 16

def areas
  @areas
end

#clear_areasObject



20
21
22
# File 'lib/rtesseract/mixed.rb', line 20

def clear_areas
  @areas = []
end

#convertObject

Convert parts of image to string



25
26
27
28
29
30
31
32
33
34
# File 'lib/rtesseract/mixed.rb', line 25

def convert
  @value = ""
  @areas.each do |area|
    image = RTesseract.new(@source.to_s,@options)
    image.crop!(area[:x].to_i, area[:y].to_i,  area[:width].to_i,  area[:height].to_i)
    @value << image.to_s
  end
rescue
  raise RTesseract::ConversionError
end

#to_sObject

Output value



37
38
39
40
41
42
43
44
45
# File 'lib/rtesseract/mixed.rb', line 37

def to_s
  return @value if @value != ""
  if @source.file?
    convert
    @value
  else
    raise RTesseract::ImageNotSelectedError
  end
end

#to_s_without_spacesObject

Remove spaces and break-lines



48
49
50
# File 'lib/rtesseract/mixed.rb', line 48

def to_s_without_spaces
  to_s.gsub(" ","").gsub("\n","").gsub("\r","")
end