Class: PdfPageCount::PdfPageCounter
- Inherits:
-
Object
- Object
- PdfPageCount::PdfPageCounter
- Defined in:
- lib/pdf-page-count/pdf_page_counter.rb
Instance Method Summary collapse
- #add_pdf_file(file) ⇒ Object
- #add_pdf_path(path, recursive: false) ⇒ Object
- #add_pdf_paths(paths, recursive: false) ⇒ Object
- #finish_counting ⇒ Object
-
#initialize ⇒ PdfPageCounter
constructor
A new instance of PdfPageCounter.
- #start_counting(threads: 10) ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize ⇒ PdfPageCounter
Returns a new instance of PdfPageCounter.
7 8 9 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 7 def initialize @total_pages = 0 end |
Instance Method Details
#add_pdf_file(file) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 33 def add_pdf_file(file) @process_pool.process do pages = PdfUtil.count_pages(file) @total_pages += pages @callback_pool.process do yield file, pages end end end |
#add_pdf_path(path, recursive: false) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 24 def add_pdf_path(path, recursive: false) files = FileUtil.find_pdf_files(path, recursive: recursive) files.each do |file| self.add_pdf_file(file) do |file, pages| yield file, pages end end end |
#add_pdf_paths(paths, recursive: false) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 16 def add_pdf_paths(paths, recursive: false) paths.each do |path| self.add_pdf_path(path, recursive: recursive) do |file, pages| yield file, pages end end end |
#finish_counting ⇒ Object
43 44 45 46 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 43 def finish_counting @process_pool.shutdown @callback_pool.shutdown end |
#start_counting(threads: 10) ⇒ Object
11 12 13 14 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 11 def start_counting(threads: 10) @process_pool = Thread.pool(threads) @callback_pool = Thread.pool(1) end |
#total_pages ⇒ Object
48 49 50 |
# File 'lib/pdf-page-count/pdf_page_counter.rb', line 48 def total_pages @total_pages end |