Быстрый фикс | Парсинг значений (-)2 в формате прочерка

This commit is contained in:
Dmitry
2026-04-18 19:04:51 +00:00
parent 3b35a63346
commit db08f63ac2
+25 -1
View File
@@ -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