From db08f63ac27397dc6451f98f55ef22c660be2c61 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 18 Apr 2026 19:04:51 +0000 Subject: [PATCH] =?UTF-8?q?=D0=91=D1=8B=D1=81=D1=82=D1=80=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20|=20=D0=9F=D0=B0=D1=80=D1=81=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20(-)2=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D1=87=D0=B5=D1=80=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/report_parser.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/services/report_parser.rb b/app/services/report_parser.rb index e035c3b..3cbed2b 100644 --- a/app/services/report_parser.rb +++ b/app/services/report_parser.rb @@ -98,7 +98,7 @@ class ReportParser { line_name: report_code.name, line_code: report_code.code, - value: source_value.presence || DEFAULT_MISSING_VALUE + value: normalized_statement_value(source_value) } end } @@ -149,6 +149,30 @@ class ReportParser value.to_s.scan(/\d+/).join.presence end + def normalized_statement_value(value) + return DEFAULT_MISSING_VALUE if value.nil? + return value if value.is_a?(Numeric) + + text = value.to_s.strip + return DEFAULT_MISSING_VALUE if text.blank? + + numeric_text?(text) ? text : DEFAULT_MISSING_VALUE + end + + def numeric_text?(text) + normalized = text.tr("\u00A0", ' ').squeeze(' ') + + integer_or_decimal = /\A[+-]?\d+(?:[.,]\d+)?\z/ + integer_or_decimal_grouped = /\A[+-]?\d{1,3}(?: \d{3})+(?:[.,]\d+)?\z/ + parenthesized_integer_or_decimal = /\A\(\d+(?:[.,]\d+)?\)\z/ + parenthesized_integer_or_decimal_grouped = /\A\(\d{1,3}(?: \d{3})+(?:[.,]\d+)?\)\z/ + + normalized.match?(integer_or_decimal) || + normalized.match?(integer_or_decimal_grouped) || + normalized.match?(parenthesized_integer_or_decimal) || + normalized.match?(parenthesized_integer_or_decimal_grouped) + end + def report_codes @report_codes ||= ReportCode.order(:code).select(:code, :name).to_a end