Skip to content

Commit 9465998

Browse files
committed
improve: extract a price when it is prefixed a euro sign
1 parent fe950ab commit 9465998

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
422422
"PMD.AvoidInstantiatingObjectsInLoops",
423423
"PMD.AvoidReassigningParameters",
424424
"PMD.NPathComplexity",
425+
"PMD.ModifiedCyclomaticComplexity",
425426
"checkstyle:parameterassignment"
426427
})
427428
/* default */ BigDecimal extractPrice(String fragment) {
@@ -437,7 +438,7 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
437438
fragment = matcher.replaceAll("$1$2");
438439
}
439440

440-
String prefix = "US$";
441+
String[] prefixes = new String[]{"US$", "€"};
441442
String postfix = "$";
442443

443444
String[] candidates = StringUtils.split(fragment, ' ');
@@ -455,9 +456,12 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
455456
if (candidate.endsWith(postfix) && candidate.length() > postfix.length()) {
456457
candidate = StringUtils.substringBeforeLast(candidate, postfix);
457458
}
458-
// "US$10" -> "10"
459-
if (candidate.startsWith(prefix) && candidate.length() > prefix.length()) {
460-
candidate = StringUtils.substringAfter(candidate, prefix);
459+
// "${prefix}10" -> "10"
460+
for (String prefix : prefixes) {
461+
if (candidate.startsWith(prefix) && candidate.length() > prefix.length()) {
462+
candidate = StringUtils.substringAfter(candidate, prefix);
463+
break;
464+
}
461465
}
462466
try {
463467
BigDecimal price = new BigDecimal(candidate);

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
@@ -660,6 +660,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
660660
'10.0 EUR' | BigDecimal.TEN
661661
'10.00 EUR' | BigDecimal.TEN
662662
'10,00 EUR' | BigDecimal.TEN
663+
'€3.50' | new BigDecimal('3.50')
663664
'10 руб 16 коп' | BigDecimal.TEN
664665
'RUB 1,218.79' | new BigDecimal('1218.79')
665666
}

0 commit comments

Comments
 (0)