Skip to content

Commit fe950ab

Browse files
committed
improve: extract a price when it contains a comma and a point in the same time (for example, 1,218.79)
1 parent 198dc33 commit fe950ab

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/java/ru/mystamps/web/feature/series/importing/SeriesInfoExtractorServiceImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
421421
@SuppressWarnings({
422422
"PMD.AvoidInstantiatingObjectsInLoops",
423423
"PMD.AvoidReassigningParameters",
424+
"PMD.NPathComplexity",
424425
"checkstyle:parameterassignment"
425426
})
426427
/* default */ BigDecimal extractPrice(String fragment) {
@@ -441,9 +442,14 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
441442

442443
String[] candidates = StringUtils.split(fragment, ' ');
443444
for (String candidate : candidates) {
444-
// replace comma with dot to handle 10,5 in the same way as 10.5
445445
if (candidate.contains(",")) {
446-
candidate = StringUtils.replaceChars(candidate, ',', '.');
446+
if (candidate.contains(".")) {
447+
// "1,218.79" => "1218.79"
448+
candidate = StringUtils.remove(candidate, ',');
449+
} else {
450+
// replace comma with dot to handle 10,5 in the same way as 10.5
451+
candidate = StringUtils.replaceChars(candidate, ',', '.');
452+
}
447453
}
448454
// "10$" -> "10"
449455
if (candidate.endsWith(postfix) && candidate.length() > postfix.length()) {

src/test/groovy/ru/mystamps/web/feature/series/importing/SeriesInfoExtractorServiceImplTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
661661
'10.00 EUR' | BigDecimal.TEN
662662
'10,00 EUR' | BigDecimal.TEN
663663
'10 руб 16 коп' | BigDecimal.TEN
664+
'RUB 1,218.79' | new BigDecimal('1218.79')
664665
}
665666

666667
@Unroll

0 commit comments

Comments
 (0)