Skip to content

Commit 0037443

Browse files
authored
✨ add missing to_s method on raw_text (#209)
1 parent e97214a commit 0037443

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

docs/code_samples/default_v2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
3333
# Send for processing
3434
response = mindee_client.enqueue_and_get_inference(
3535
input_source,
36-
inference_params # Note: this parameter can also be provided as a Hash.
36+
inference_params # This parameter can also be provided as a Hash.
3737
)
3838

3939
# Print a brief summary of the parsed data

lib/mindee/parsing/v2/raw_text.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def initialize(server_response)
1515
@pages.push RawTextPage.new(page)
1616
end
1717
end
18+
19+
def to_s
20+
"#{@pages.map(&:to_s).join("\n\n")}\n"
21+
end
1822
end
1923
end
2024
end

lib/mindee/parsing/v2/raw_text_page.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ module Parsing
55
module V2
66
# Raw text extracted from a single page.
77
class RawTextPage
8-
# @return [Boolean] Text content of the page as a single string. '\n' is used to separate lines.
8+
# @return [String] Text content of the page as a single string. '\n' is used to separate lines.
99
attr_reader :content
1010

1111
# @param server_response [Hash] Raw JSON parsed into a Hash.
1212
def initialize(server_response)
1313
@content = server_response['content']
1414
end
15+
16+
def to_s
17+
@content
18+
end
1519
end
1620
end
1721
end

sig/mindee/parsing/v2/raw_text_page.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Mindee
22
module Parsing
33
module V2
44
class RawTextPage
5-
attr_reader content: string
5+
attr_reader content: String
66

77
def initialize: (Hash[String | Symbol, untyped]) -> void
88
end

spec/parsing/v2/inference_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
let(:standard_field_path) { File.join(inference_path, 'standard_field_types.json') }
1111
let(:standard_field_rst_path) { File.join(inference_path, 'standard_field_types.rst') }
1212
let(:location_field_path) { File.join(findoc_path, 'complete_with_coordinates.json') }
13-
let(:raw_text_path) { File.join(inference_path, 'raw_texts.json') }
13+
let(:raw_text_json_path) { File.join(inference_path, 'raw_texts.json') }
14+
let(:raw_text_str_path) { File.join(inference_path, 'raw_texts.txt') }
1415
let(:blank_path) { File.join(findoc_path, 'blank.json') }
1516
let(:complete_path) { File.join(findoc_path, 'complete.json') }
1617

@@ -268,7 +269,7 @@ def load_standard_fields
268269

269270
describe 'raw_text' do
270271
it 'exposes raw texts' do
271-
response = load_v2_inference(raw_text_path)
272+
response = load_v2_inference(raw_text_json_path)
272273

273274
active_options = response.inference.active_options
274275
expect(active_options).not_to be_nil
@@ -278,10 +279,16 @@ def load_standard_fields
278279
expect(raw_text).not_to be_nil
279280
expect(raw_text).to be_a(Mindee::Parsing::V2::RawText)
280281

282+
expect(raw_text.to_s).to eq(File.read(raw_text_str_path, encoding: 'UTF-8'))
283+
281284
expect(raw_text.pages.length).to eq(2)
282285
first = raw_text.pages.first
283286
expect(first).to be_a(Mindee::Parsing::V2::RawTextPage)
284287
expect(first.content).to eq('This is the raw text of the first page...')
288+
289+
raw_text.pages.each do |page|
290+
expect(page.content).to be_a(String)
291+
end
285292
end
286293
end
287294

0 commit comments

Comments
 (0)