Class: OCRDocument
- Inherits:
-
Object
- Object
- OCRDocument
- Defined in:
- lib/ocr_document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #add_image_to_page(page_number, image_path) ⇒ Object
- #add_page(file) ⇒ Object (also: #add_file)
- #add_pages(list_o_pages) ⇒ Object (also: #add_files)
- #each_line ⇒ Object
- #each_page ⇒ Object
- #each_word ⇒ Object
-
#initialize ⇒ OCRDocument
constructor
A new instance of OCRDocument.
- #page(number) ⇒ Object
Constructor Details
#initialize ⇒ OCRDocument
Returns a new instance of OCRDocument.
8 9 10 11 |
# File 'lib/ocr_document.rb', line 8 def initialize @pages = Hash.new() @page_count = 0 end |
Instance Attribute Details
#page_count ⇒ Object (readonly)
Returns the value of attribute page_count.
6 7 8 |
# File 'lib/ocr_document.rb', line 6 def page_count @page_count end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
6 7 8 |
# File 'lib/ocr_document.rb', line 6 def pages @pages end |
Instance Method Details
#add_image_to_page(page_number, image_path) ⇒ Object
26 27 28 |
# File 'lib/ocr_document.rb', line 26 def add_image_to_page(page_number, image_path) @pages[page_number].image = image_path end |
#add_page(file) ⇒ Object Also known as: add_file
20 21 22 23 24 |
# File 'lib/ocr_document.rb', line 20 def add_page( file ) page = OCRPage.new( file ) @pages[page.page_number] = page @page_count += 1 end |
#add_pages(list_o_pages) ⇒ Object Also known as: add_files
13 14 15 16 17 18 |
# File 'lib/ocr_document.rb', line 13 def add_pages( list_o_pages ) raise "no files given" if list_o_pages.empty? list_o_pages.each do |file| add_page(file) end end |
#each_line ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ocr_document.rb', line 41 def each_line for page in @pages.values do page.each_line do |line| yield line end end end |
#each_page ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ocr_document.rb', line 34 def each_page sorted_pages = @pages.keys.sort sorted_pages.each do |page_key| yield @pages[page_key] end end |
#each_word ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/ocr_document.rb', line 49 def each_word for page in @pages.values do page.each_line do |line| line.each do |word| yield word end end end end |
#page(number) ⇒ Object
30 31 32 |
# File 'lib/ocr_document.rb', line 30 def page( number ) @pages[number] end |