Class: Bagira
- Inherits:
-
Object
- Object
- Bagira
- Defined in:
- lib/bagira.rb,
lib/bagira/version.rb
Constant Summary collapse
- FILE_TYPE =
{ :invalid => 'invalid', :not_found => 'not_found', :pdf => 'pdf', :jpg => 'jpg', :png => 'png' }
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
Instance Method Summary collapse
-
#initialize(filepath) ⇒ Bagira
constructor
A new instance of Bagira.
- #perform_ocr ⇒ Object
Constructor Details
#initialize(filepath) ⇒ Bagira
Returns a new instance of Bagira.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bagira.rb', line 12 def initialize(filepath) @file_type = FILE_TYPE[:invalid] @file_type = FILE_TYPE[:pdf] unless filepath.match(/\.pdf$/).nil? @file_type = FILE_TYPE[:png] unless filepath.match(/\.png$/).nil? @file_type = FILE_TYPE[:jpg] unless filepath.match(/\.jpg$/).nil? @file_type = FILE_TYPE[:not_found] unless File.exist?(filepath) @filepath = filepath @page_count = 0 @page_count = 1 if is_image? if is_document? reader = PDF::Reader.new(filepath) @page_count = reader.page_count end end |
Instance Attribute Details
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
8 9 10 |
# File 'lib/bagira.rb', line 8 def file_type @file_type end |
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
9 10 11 |
# File 'lib/bagira.rb', line 9 def filepath @filepath end |
#page_count ⇒ Object (readonly)
Returns the value of attribute page_count.
10 11 12 |
# File 'lib/bagira.rb', line 10 def page_count @page_count end |
Instance Method Details
#perform_ocr ⇒ Object
29 30 31 32 |
# File 'lib/bagira.rb', line 29 def perform_ocr return process_image(@filepath) if is_image? return process_pdf(@filepath) if is_document? end |