Sha256: 1ea8929759a263096e2a1ee66d080cf66485ba8d7533e02bf4e550fea674bef4

Contents?: true

Size: 1.73 KB

Versions: 21

Compression:

Stored size: 1.73 KB

Contents

class Sqed

  # A Sqed::Result is a container for the results of the
  # the data extraction for the full stage
  #
  class Result
    SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
      attr_accessor "#{k}_image".to_sym

      # @return [Hash] `barcode: '', text: ''`
      attr_accessor k
    end

    # @return [Hash] of `section_type: [ ]`
    attr_accessor :boundary_coordinates

    # @return [Array]
    #   of section type
    attr_accessor :sections

    def initialize
      @boundary_coordinates = {}
      SqedConfig::LAYOUT_SECTION_TYPES.each do |k|
        send("#{k}=", {})
        @boundary_coordinates[k] = [nil, nil, nil, nil]
      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 = send(k)
        result[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 = send("#{k}_image")
        result[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
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
sqed-0.8.3 lib/sqed/result.rb
sqed-0.8.2 lib/sqed/result.rb
sqed-0.8.1 lib/sqed/result.rb
sqed-0.8.0 lib/sqed/result.rb
sqed-0.7.1 lib/sqed/result.rb
sqed-0.7.0 lib/sqed/result.rb
sqed-0.6.0 lib/sqed/result.rb
sqed-0.5.8 lib/sqed/result.rb
sqed-0.5.7 lib/sqed/result.rb
sqed-0.5.6 lib/sqed/result.rb
sqed-0.5.5 lib/sqed/result.rb
sqed-0.5.4 lib/sqed/result.rb
sqed-0.5.3 lib/sqed/result.rb
sqed-0.5.2 lib/sqed/result.rb
sqed-0.5.1 lib/sqed/result.rb
sqed-0.5.0 lib/sqed/result.rb
sqed-0.4.4 lib/sqed/result.rb
sqed-0.4.3 lib/sqed/result.rb
sqed-0.4.2 lib/sqed/result.rb
sqed-0.4.1 lib/sqed/result.rb