Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/_test-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Run Tests
timeout-minutes: 30
strategy:
max-parallel: 4
max-parallel: 6
matrix:
os_config:
- os: "ubuntu-24.04"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test-integration-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 3
max-parallel: 4
matrix:
os:
- "ubuntu-24.04"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 3
max-parallel: 4
matrix:
os:
- "ubuntu-24.04"
Expand Down
32 changes: 32 additions & 0 deletions lib/mindee/v2/parsing/field/simple_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ def to_s
end
end

# Retrieves the field value as a Float.
# @return [Float, nil]
# @raise [RuntimeError] If the value is not a Float.
def float_value
raise "Value is not a float: #{@value.class}" unless @value.nil? || @value.is_a?(Float)

val = @value
val.is_a?(Float) ? val : nil # @type var val: Float | nil
end

# Retrieves the field value as a String.
# @return [String, nil]
# @raise [RuntimeError] If the value is not a String.
def string_value
raise "Value is not a string: #{@value.class}" unless @value.nil? || @value.is_a?(String)

val = @value
val.is_a?(String) ? val : nil # @type var val: String | nil
end

# Retrieves the field value as a Boolean.
# @return [Boolean, nil]
# @raise [RuntimeError] If the value is not a Boolean.
def boolean_value
unless @value.nil? || @value.is_a?(TrueClass) || @value.is_a?(FalseClass)
raise "Value is not a boolean: #{@value.class}"
end

val = @value
@value.is_a?(TrueClass) || @value.is_a?(FalseClass) ? val : nil # @type var val: bool | nil
end

private

# Format numeric values to display '.0' in string reps.
Expand Down
6 changes: 5 additions & 1 deletion sig/mindee/v2/parsing/field/simple_field.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ module Mindee
module Parsing
module Field
class SimpleField < BaseField
attr_reader value: String | Integer | Float | bool | nil
attr_reader value: String | Float | bool | nil

def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void
def boolean_value: -> (bool | nil)
def float_value: -> (Float | nil)
def string_value: -> (String | nil)

def to_s: -> String
def format_numeric_value: (Integer | Float) -> String
end
Expand Down
4 changes: 2 additions & 2 deletions spec/v2/client_v2_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
fields = result.fields
expect(fields).not_to be_nil
expect(fields['supplier_name']).not_to be_nil
expect(fields['supplier_name'].value).to eq('John Smith')
expect(fields['supplier_name'].string_value).to eq('John Smith')
end
end
context 'An error' do
Expand Down Expand Up @@ -266,7 +266,7 @@
fields = result.fields
expect(fields).not_to be_nil
expect(fields['test_replace']).not_to be_nil
expect(fields['test_replace'].value).to eq('a test value')
expect(fields['test_replace'].string_value).to eq('a test value')
end
end
end
2 changes: 1 addition & 1 deletion spec/v2/product/classification/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

expect(classification.extraction_response).to be_a(Mindee::V2::Product::Extraction::ExtractionResponse)
expect(
classification.extraction_response.inference.result.fields.get_simple_field('customer_name').value
classification.extraction_response.inference.result.fields.get_simple_field('customer_name').string_value
).to eq('Jiro Doi')
end
end
4 changes: 2 additions & 2 deletions spec/v2/product/crop/crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
extraction_response0 = crop0.extraction_response
expect(extraction_response0).not_to be_nil
expect(
extraction_response0.inference.result.fields.get_simple_field('supplier_name').value
extraction_response0.inference.result.fields.get_simple_field('supplier_name').string_value
).to eq('CHEZ ALAIN MIAM MIAM')

crop1 = crops[1]
Expand All @@ -110,7 +110,7 @@
extraction_response1 = crop1.extraction_response
expect(extraction_response1).not_to be_nil
expect(
extraction_response1.inference.result.fields.get_simple_field('supplier_name').value
extraction_response1.inference.result.fields.get_simple_field('supplier_name').string_value
).to eq('La cerise sur la pizza')
end
end
15 changes: 11 additions & 4 deletions spec/v2/product/extraction/extraction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def load_v2_extraction_inference(resource_path)
expect(line_items).to be_a(list_field)
first_line_item = line_items.object_items[0]
expect(first_line_item).to be_a(object_field)
expect(first_line_item.get_simple_field('quantity').value).to eq(1.0)
expect(first_line_item.get_simple_field('quantity').float_value).to eq(1.0)

base_field = tax_item_obj.fields.get_simple_field('base')
expect(base_field).to be_a(simple_field)
expect(base_field.value).to eq(31.5)
expect(base_field.float_value).to eq(31.5)

expect(fields).to have_key('supplier_address')
supplier_address = fields.get_object_field('supplier_address')
Expand All @@ -138,14 +138,14 @@ def load_v2_extraction_inference(resource_path)

country_field = supplier_address.fields.get_simple_field('country')
expect(country_field).to be_a(simple_field)
expect(country_field.value).to eq('USA')
expect(country_field.string_value).to eq('USA')
expect(country_field.to_s).to eq('USA')

customer_addr = fields.get_object_field('customer_address')
expect(customer_addr).to be_a(object_field)
city_field = customer_addr.fields.get_simple_field('city')
expect(city_field).to be_a(simple_field)
expect(city_field.value).to eq('New York')
expect(city_field.string_value).to eq('New York')

expect(inference.result.raw_text).to be_nil
end
Expand Down Expand Up @@ -213,25 +213,32 @@ def load_standard_fields
field_simple_string = fields.get_simple_field('field_simple_string')
expect(field_simple_string).to be_a(simple_field)
expect(field_simple_string.value).to eq('field_simple_string-value')
expect(field_simple_string.string_value).to eq('field_simple_string-value')
expect(field_simple_string.confidence).to eq(field_confidence::CERTAIN)
expect(field_simple_string.to_s).to eq('field_simple_string-value')

field_simple_int = fields.get_simple_field('field_simple_int')
expect(field_simple_int).to be_a(simple_field)
expect(field_simple_int.value).to be_a(Float)
expect(field_simple_int.float_value).to eq(12.0)

field_simple_float = fields.get_simple_field('field_simple_float')
expect(field_simple_float).to be_a(simple_field)
expect(field_simple_float.value).to be_a(Float)
expect(field_simple_float.value).to eq(1.1)

field_simple_bool = fields.get_simple_field('field_simple_bool')
expect(field_simple_bool).to be_a(simple_field)
expect(field_simple_bool.value).to eq(true)
expect(field_simple_bool.boolean_value).to eq(true)
expect(field_simple_bool.to_s).to eq('True')

field_simple_null = fields.get_simple_field('field_simple_null')
expect(field_simple_null).to be_a(simple_field)
expect(field_simple_null.value).to be_nil
expect(field_simple_null.string_value).to be_nil
expect(field_simple_null.float_value).to be_nil
expect(field_simple_null.boolean_value).to be_nil
expect(field_simple_null.to_s).to eq('')
end

Expand Down
4 changes: 2 additions & 2 deletions spec/v2/product/split/split_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
extraction_response0 = split0.extraction_response
expect(extraction_response0).not_to be_nil
expect(
extraction_response0.inference.result.fields.get_simple_field('supplier_phone_number').value
extraction_response0.inference.result.fields.get_simple_field('supplier_phone_number').string_value
).to eq('05 05 44 44 90')

split1 = splits[1]
Expand All @@ -75,7 +75,7 @@
extraction_response1 = split1.extraction_response
expect(extraction_response1).not_to be_nil
expect(
extraction_response1.inference.result.fields.get_simple_field('supplier_phone_number').value
extraction_response1.inference.result.fields.get_simple_field('supplier_phone_number').string_value
).to eq('416-555-1212')
end
end
Loading