Class: Tabula::ObjectExtractor
- Inherits:
-
Object
- Object
- Tabula::ObjectExtractor
- Defined in:
- lib/tabula/pdf/object_extractor.rb
Overview
Extracts content from PDF documents. Wraps pdf-reader and provides access to pages with text and rulings.
Defined Under Namespace
Classes: RulingReceiver
Instance Attribute Summary collapse
-
#pdf_reader ⇒ Object
readonly
Returns the value of attribute pdf_reader.
Class Method Summary collapse
-
.open(path, password: nil) {|ObjectExtractor| ... } ⇒ ObjectExtractor, Object
Open a PDF file for extraction.
Instance Method Summary collapse
-
#close ⇒ Object
Close the PDF.
- #closed? ⇒ Boolean
-
#extract ⇒ PageIterator
Extract all pages.
-
#extract_page(page_number) ⇒ Page
Extract a specific page.
-
#extract_pages(pages) ⇒ PageIterator
Extract specific pages.
-
#initialize(path, password: nil) ⇒ ObjectExtractor
constructor
A new instance of ObjectExtractor.
-
#page_count ⇒ Integer
Get page count.
-
#pages ⇒ Enumerator
Get pages iterator.
Constructor Details
#initialize(path, password: nil) ⇒ ObjectExtractor
Returns a new instance of ObjectExtractor.
31 32 33 34 35 36 |
# File 'lib/tabula/pdf/object_extractor.rb', line 31 def initialize(path, password: nil) @path = path @password = password @pdf_reader = open_pdf @closed = false end |
Instance Attribute Details
#pdf_reader ⇒ Object (readonly)
Returns the value of attribute pdf_reader.
9 10 11 |
# File 'lib/tabula/pdf/object_extractor.rb', line 9 def pdf_reader @pdf_reader end |
Class Method Details
.open(path, password: nil) {|ObjectExtractor| ... } ⇒ ObjectExtractor, Object
Open a PDF file for extraction
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tabula/pdf/object_extractor.rb', line 16 def self.open(path, password: nil, &block) extractor = new(path, password: password) if block begin yield extractor ensure extractor.close end else extractor end end |
Instance Method Details
#close ⇒ Object
Close the PDF
74 75 76 |
# File 'lib/tabula/pdf/object_extractor.rb', line 74 def close @closed = true end |
#closed? ⇒ Boolean
78 79 80 |
# File 'lib/tabula/pdf/object_extractor.rb', line 78 def closed? @closed end |
#extract ⇒ PageIterator
Extract all pages
50 51 52 |
# File 'lib/tabula/pdf/object_extractor.rb', line 50 def extract extract_pages(1..page_count) end |
#extract_page(page_number) ⇒ Page
Extract a specific page
41 42 43 44 45 46 |
# File 'lib/tabula/pdf/object_extractor.rb', line 41 def extract_page(page_number) validate_page_number(page_number) pdf_page = @pdf_reader.pages[page_number - 1] process_page(pdf_page, page_number) end |
#extract_pages(pages) ⇒ PageIterator
Extract specific pages
57 58 59 |
# File 'lib/tabula/pdf/object_extractor.rb', line 57 def extract_pages(pages) PageIterator.new(self, pages.to_a) end |
#page_count ⇒ Integer
Get page count
63 64 65 |
# File 'lib/tabula/pdf/object_extractor.rb', line 63 def page_count @pdf_reader.page_count end |
#pages ⇒ Enumerator
Get pages iterator
69 70 71 |
# File 'lib/tabula/pdf/object_extractor.rb', line 69 def pages (1..page_count).lazy.map { |n| extract_page(n) } end |