Class: Rocrad
- Inherits:
-
Object
- Object
- Rocrad
- Defined in:
- lib/rocrad.rb,
lib/rocrad/mixed.rb,
lib/rocrad/binary.rb,
lib/rocrad/errors.rb
Defined Under Namespace
Classes: Binary, ImageNotSelectedError, Mixed, UnsupportedFileTypeError
Instance Attribute Summary collapse
-
#src ⇒ Object
Returns the value of attribute src.
-
#tmp ⇒ Object
readonly
Returns the value of attribute tmp.
-
#txt ⇒ Object
readonly
Returns the value of attribute txt.
Instance Method Summary collapse
-
#crop!(x, y, w, h) ⇒ Object
Crop image to convert.
-
#initialize(src = "") ⇒ Rocrad
constructor
A new instance of Rocrad.
- #ocr! ⇒ Object
-
#to_s ⇒ Object
Output value.
Constructor Details
#initialize(src = "") ⇒ Rocrad
Returns a new instance of Rocrad.
16 17 18 19 20 21 |
# File 'lib/rocrad.rb', line 16 def initialize(src="") @uid = UUID.new @src = build_source src @txt = "" @tmp = nil end |
Instance Attribute Details
#src ⇒ Object
Returns the value of attribute src.
13 14 15 |
# File 'lib/rocrad.rb', line 13 def src @src end |
#tmp ⇒ Object (readonly)
Returns the value of attribute tmp.
14 15 16 |
# File 'lib/rocrad.rb', line 14 def tmp @tmp end |
#txt ⇒ Object (readonly)
Returns the value of attribute txt.
14 15 16 |
# File 'lib/rocrad.rb', line 14 def txt @txt end |
Instance Method Details
#crop!(x, y, w, h) ⇒ Object
Crop image to convert
46 47 48 49 50 51 52 53 |
# File 'lib/rocrad.rb', line 46 def crop!(x, y, w, h) @txt = "" src = Magick::Image.read(@src.to_s).first src.crop!(x, y, w, h) @tmp = Pathname.new(Dir::tmpdir).join("#{@uid.generate}_#{@src.sub(@src.extname, "-crop#{@src.extname}").basename}") src.write @tmp.to_s self end |
#ocr! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rocrad.rb', line 28 def ocr! if @src.instance_of? Pathname and @src.file? ocr_via_path @txt elsif @src.instance_of? URI::HTTP ocr_via_http @txt else raise ImageNotSelectedError end end |
#to_s ⇒ Object
Output value
41 42 43 |
# File 'lib/rocrad.rb', line 41 def to_s @txt != "" ? @txt : ocr! end |