Class: Mindee::V2::Product::Crop::CropItem

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v2/product/crop/crop_item.rb

Overview

Result of a cropped document region.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_response) ⇒ CropItem

Returns a new instance of CropItem.

Parameters:

  • server_response (Hash)

    Hash representation of the JSON returned by the service.



16
17
18
19
20
21
22
23
24
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 16

def initialize(server_response)
  @object_type = server_response['object_type']
  @location = Mindee::V2::Parsing::Field::FieldLocation.new(server_response['location'])
  # rubocop:disable Style/GuardClause
  unless server_response['extraction_response'].nil?
    @extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
  end
  # rubocop:enable Style/GuardClause
end

Instance Attribute Details

#extraction_responseObject (readonly)

Returns the value of attribute extraction_response.



13
14
15
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 13

def extraction_response
  @extraction_response
end

#locationV2::Parsing::Field::FieldLocation (readonly)

Returns Coordinates of the detected object on the document.

Returns:



12
13
14
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 12

def location
  @location
end

#object_typeString (readonly)

Returns Type or classification of the detected object.

Returns:

  • (String)

    Type or classification of the detected object.



10
11
12
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 10

def object_type
  @object_type
end

Instance Method Details

#extract_from_file(input_source) ⇒ ExtractedImage

Extract all crop items from this page

Parameters:

Returns:

  • (ExtractedImage)


36
37
38
39
40
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 36

def extract_from_file(input_source)
  Image::ImageExtractor.extract_multiple_images_from_source(
    input_source, @location.page, [@location.polygon]
  )[0]
end

#to_sString

String representation.

Returns:

  • (String)


28
29
30
# File 'lib/mindee/v2/product/crop/crop_item.rb', line 28

def to_s
  "* :Location: #{location}\n  :Object Type: #{object_type}"
end