Class: Sqed::Result
- Inherits:
-
Object
- Object
- Sqed::Result
- Defined in:
- lib/sqed/result.rb
Overview
A Sqed::Result is a container for the results of the the data extraction for the full stage
Instance Attribute Summary collapse
-
#boundary_coordinates ⇒ Hash
Of ‘section_type: [ ]`.
-
#sections ⇒ Array
Of section type.
Instance Method Summary collapse
-
#barcode_text_for(section) ⇒ Object
return [String, nil] the text derived from the barcode parsing of the section.
-
#images ⇒ Object
return [Hash] a map of layout_section_type => Rmagick::Image.
-
#initialize ⇒ Result
constructor
A new instance of Result.
-
#text ⇒ Object
return [Hash] a map of layout_section_type => value (if there is a value), i.e.
-
#text_for(section) ⇒ Object
return [String, nil] the text derived from the OCR parsing of the section.
-
#write_images ⇒ Object
return [True] write the images in #images to tmp/.
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
21 22 23 24 25 26 27 |
# File 'lib/sqed/result.rb', line 21 def initialize @boundary_coordinates = {} SqedConfig::LAYOUT_SECTION_TYPES.each do |k| send("#{k}=", {}) @boundary_coordinates[k] = [nil, nil, nil, nil] end end |
Instance Attribute Details
#boundary_coordinates ⇒ Hash
Returns of ‘section_type: [ ]`.
15 16 17 |
# File 'lib/sqed/result.rb', line 15 def boundary_coordinates @boundary_coordinates end |
#sections ⇒ Array
Returns of section type.
19 20 21 |
# File 'lib/sqed/result.rb', line 19 def sections @sections end |
Instance Method Details
#barcode_text_for(section) ⇒ Object
return [String, nil]
the text derived from the parsing of the section
37 38 39 |
# File 'lib/sqed/result.rb', line 37 def (section) send(section)[:barcode] end |
#images ⇒ Object
return [Hash]
a map of layout_section_type => Rmagick::Image
55 56 57 58 59 60 61 62 |
# File 'lib/sqed/result.rb', line 55 def images result = {} SqedConfig::LAYOUT_SECTION_TYPES.each do |k| image = send("#{k}_image") result[k] = image if image end result end |
#text ⇒ Object
return [Hash]
a map of layout_section_type => value (if there is a value),
i.e. all possible parsed text values returned from the parser
44 45 46 47 48 49 50 51 |
# File 'lib/sqed/result.rb', line 44 def text result = {} SqedConfig::LAYOUT_SECTION_TYPES.each do |k| v = send(k) result[k] = v if v[:barcode] || v[:text] end result end |
#text_for(section) ⇒ Object
return [String, nil]
the text derived from the OCR parsing of the section
31 32 33 |
# File 'lib/sqed/result.rb', line 31 def text_for(section) send(section)[:text] end |
#write_images ⇒ Object
return [True]
write the images in #images to tmp/
66 67 68 69 70 71 |
# File 'lib/sqed/result.rb', line 66 def write_images images.each do |k, img| img.write("tmp/#{k}.jpg") end true end |