Class: RTesseract::Mixed
- Inherits:
-
Object
- Object
- RTesseract::Mixed
- Defined in:
- lib/rtesseract/mixed.rb
Overview
Class to read an image from specified areas
Instance Attribute Summary collapse
-
#areas ⇒ Object
readonly
Returns the value of attribute areas.
Instance Method Summary collapse
- #area(x, y, width, height) ⇒ 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.
7 8 9 10 11 12 13 |
# File 'lib/rtesseract/mixed.rb', line 7 def initialize(src = '', = {}) @source = Pathname.new src @options = @value = '' @areas = .delete(:areas) || [] yield self if block_given? end |
Instance Attribute Details
#areas ⇒ Object (readonly)
Returns the value of attribute areas.
5 6 7 |
# File 'lib/rtesseract/mixed.rb', line 5 def areas @areas end |
Instance Method Details
#area(x, y, width, height) ⇒ Object
15 16 17 18 |
# File 'lib/rtesseract/mixed.rb', line 15 def area(x, y, width, height) @value = '' @areas << { x: x, y: y, width: width, height: height } 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 |
# File 'lib/rtesseract/mixed.rb', line 25 def convert @value = [] @areas.each_with_object(RTesseract.new(@source.to_s, @options.dup)) do |area, image| image.crop!(area[:x], area[:y], area[:width], area[:height]) @value << image.to_s end rescue => error raise RTesseract::ConversionError.new(error), error, caller end |
#to_s ⇒ Object
Output value
36 37 38 39 40 41 42 43 44 |
# File 'lib/rtesseract/mixed.rb', line 36 def to_s return @value if @value != '' if @source.file? convert @value.join else fail RTesseract::ImageNotSelectedError.new(@source) end end |
#to_s_without_spaces ⇒ Object
Remove spaces and break-lines
47 48 49 |
# File 'lib/rtesseract/mixed.rb', line 47 def to_s_without_spaces to_s.gsub(' ', '').gsub("\n", '').gsub("\r", '') end |