Быстрый фикс | Парсинг значений (-)2 в формате прочерка
This commit is contained in:
@@ -98,7 +98,7 @@ class ReportParser
|
|||||||
{
|
{
|
||||||
line_name: report_code.name,
|
line_name: report_code.name,
|
||||||
line_code: report_code.code,
|
line_code: report_code.code,
|
||||||
value: source_value.presence || DEFAULT_MISSING_VALUE
|
value: normalized_statement_value(source_value)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -149,6 +149,30 @@ class ReportParser
|
|||||||
value.to_s.scan(/\d+/).join.presence
|
value.to_s.scan(/\d+/).join.presence
|
||||||
end
|
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
|
def report_codes
|
||||||
@report_codes ||= ReportCode.order(:code).select(:code, :name).to_a
|
@report_codes ||= ReportCode.order(:code).select(:code, :name).to_a
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user