Class: Sqed::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeResult

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_coordinatesHash

Returns of ‘section_type: [ ]`.

Returns:

  • (Hash)

    of ‘section_type: [ ]`



15
16
17
# File 'lib/sqed/result.rb', line 15

def boundary_coordinates
  @boundary_coordinates
end

#sectionsArray

Returns of section type.

Returns:

  • (Array)

    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 barcode parsing of the section


37
38
39
# File 'lib/sqed/result.rb', line 37

def barcode_text_for(section)
  send(section)[:barcode]
end

#imagesObject

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

#textObject

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_imagesObject

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