Sha256: 4f87d7238e9ff4c7783b714116b97b332152c0708f58f4b9844dfb4a710ed1ef

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# A Sqed::Result is a container for the results of the
# the data extraction for the full stage 
#
class Sqed::Result

  SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
    attr_accessor "#{k}_image".to_sym
    attr_accessor k
  end

  def initialize
    SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
      send("#{k}=", {}) 
    end
  end

  # return [String, nil]
  #   the text derived from the OCR parsing of the section
  def text_for(section)
    send(section)[:text] 
  end

  # return [String, nil]
  #   the text derived from the barcode parsing of the section
  def barcode_text_for(section)
    send(section)[:barcode]
  end

  # 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
  def text
    result = {} 
    SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
      v = self.send(k)
      result.merge!(k => v) if v[:barcode] || v[:text] 
    end
    result
  end

  # return [Hash]
  #   a map of layout_section_type => Rmagick::Image
  def images
    result = {} 
    SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
      image = self.send("#{k}_image")
      result.merge!(k => image) if image
    end
    result
  end

  # return [True]
  #   write the images in #images to tmp/ 
  def write_images
    images.each do |k, img|
      img.write("tmp/#{k}.jpg")
    end
    true
  end

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sqed-0.1.1 lib/sqed/result.rb