Class: RTesseract::Mixed
- Inherits:
-
Object
- Object
- RTesseract::Mixed
- Defined in:
- lib/rtesseract/mixed.rb
Instance Method Summary collapse
- #area(x, y, width, height) ⇒ Object
- #areas ⇒ Object
- #clear_areas ⇒ Object
-
#convert ⇒ Object
Convert parts of image to string.
-
#initialize(src = "", options = {}) {|_self| ... } ⇒ Mixed
constructor
A new instance of Mixed.
-
#to_s ⇒ Object
Output value.
-
#to_s_without_spaces ⇒ Object
Remove spaces and break-lines.
Constructor Details
#initialize(src = "", options = {}) {|_self| ... } ⇒ Mixed
Returns a new instance of Mixed.
3 4 5 6 7 8 9 |
# File 'lib/rtesseract/mixed.rb', line 3 def initialize(src="", ={}) @source = Pathname.new src @options = @value = "" @areas = .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 |
#areas ⇒ Object
16 17 18 |
# File 'lib/rtesseract/mixed.rb', line 16 def areas @areas end |
#clear_areas ⇒ Object
20 21 22 |
# File 'lib/rtesseract/mixed.rb', line 20 def clear_areas @areas = [] end |
#convert ⇒ Object
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_s ⇒ Object
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_spaces ⇒ Object
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 |