Skip to content

Commit 41d5c28

Browse files
committed
fix(series import): extract currency when price ends with a dollar sign.
Fix #1275
1 parent 362a72e commit 41d5c28

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class SeriesInfoExtractorServiceImpl implements SeriesInfoExtractorServic
7676
// Regular expression that matches Ukrainian hryvnia.
7777
private static final Pattern UAH_CURRENCY_REGEXP = Pattern.compile("[0-9] грн");
7878

79+
// Regular expression that matches US dollar.
80+
private static final Pattern USD_CURRENCY_REGEXP = Pattern.compile("[0-9]\\$");
81+
7982
// CheckStyle: ignore LineLength for next 4 lines
8083
private static final Pattern VALID_CATEGORY_NAME_EN = Pattern.compile(CategoryValidation.NAME_EN_REGEXP);
8184
private static final Pattern VALID_CATEGORY_NAME_RU = Pattern.compile(CategoryValidation.NAME_RU_REGEXP);
@@ -456,6 +459,12 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
456459
return Currency.UAH.toString();
457460
}
458461

462+
matcher = USD_CURRENCY_REGEXP.matcher(fragment);
463+
if (matcher.find()) {
464+
log.debug("Currency is USD");
465+
return Currency.USD.toString();
466+
}
467+
459468
log.debug("Could not extract currency from a fragment");
460469

461470
return null;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,13 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
693693
'135.74 грн' | _
694694
}
695695

696+
@Unroll
697+
def 'extractCurrency() should extract USD currency from "#fragment"'(String fragment) {
698+
expect:
699+
service.extractCurrency(fragment) == 'USD'
700+
where:
701+
fragment | _
702+
'1,36$' | _
703+
}
704+
696705
}

0 commit comments

Comments
 (0)