Skip to content

Commit 9479b21

Browse files
committed
improve: extract a price when it is prefixed with "US$"
1 parent 8989796 commit 9479b21

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
435435
if (matcher.find()) {
436436
fragment = matcher.replaceAll("$1$2");
437437
}
438+
439+
String prefix = "US$";
438440

439441
String[] candidates = StringUtils.split(fragment, ' ');
440442
for (String candidate : candidates) {
@@ -446,6 +448,10 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
446448
if (candidate.endsWith("$") && candidate.length() >= 2) {
447449
candidate = candidate.substring(0, candidate.length() - 1);
448450
}
451+
// "US$10" -> "10"
452+
if (candidate.startsWith(prefix) && candidate.length() > prefix.length()) {
453+
candidate = StringUtils.substringAfter(candidate, prefix);
454+
}
449455
try {
450456
BigDecimal price = new BigDecimal(candidate);
451457
log.debug("Price is {}", price);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,15 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
647647
}
648648

649649
@Unroll
650+
@SuppressWarnings('UnnecessaryBigDecimalInstantiation')
650651
def 'extractPrice() should extract "#expected" from "#fragment"'(String fragment, BigDecimal expected) {
651652
expect:
652653
service.extractPrice(fragment) == expected
653654
where:
654655
fragment | expected
655656
'1$' | BigDecimal.ONE
656657
'10$' | BigDecimal.TEN
658+
'US$16.50' | new BigDecimal('16.50')
657659
'10 EUR' | BigDecimal.TEN
658660
'10.0 EUR' | BigDecimal.TEN
659661
'10.00 EUR' | BigDecimal.TEN

0 commit comments

Comments
 (0)