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(points) ⇒ Object
Add areas.
-
#clear_areas ⇒ Object
Clear areas.
-
#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.
8 9 10 11 12 13 14 |
# File 'lib/rtesseract/mixed.rb', line 8 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.
6 7 8 |
# File 'lib/rtesseract/mixed.rb', line 6 def areas @areas end |
Instance Method Details
#area(points) ⇒ Object
Add areas
17 18 19 20 |
# File 'lib/rtesseract/mixed.rb', line 17 def area(points) @value = '' @areas << points end |
#clear_areas ⇒ Object
Clear areas
23 24 25 |
# File 'lib/rtesseract/mixed.rb', line 23 def clear_areas @areas = [] end |
#convert ⇒ Object
Convert parts of image to string
28 29 30 31 32 33 34 35 36 |
# File 'lib/rtesseract/mixed.rb', line 28 def convert @value = [] @areas.each_with_object(RTesseract.new(@source.to_s, @options.dup)) do |area, image| image.crop!(area) @value << image.to_s end rescue => error raise RTesseract::ConversionError.new(error), error, caller end |
#to_s ⇒ Object
Output value
39 40 41 42 43 44 45 46 47 |
# File 'lib/rtesseract/mixed.rb', line 39 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
50 51 52 |
# File 'lib/rtesseract/mixed.rb', line 50 def to_s_without_spaces to_s.delete(' ').delete("\n").delete("\r") end |