Skip to content

Commit 2c47551

Browse files
committed
improve: detect euro currency when a price is prefixed with a euro sign
1 parent 9465998 commit 2c47551

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
@@ -80,6 +80,9 @@ public class SeriesInfoExtractorServiceImpl implements SeriesInfoExtractorServic
8080
// Regular expression that matches Rubles (Russian currency).
8181
// CheckStyle: ignore LineLength for next 1 line
8282
private static final Pattern RUB_CURRENCY_REGEXP = Pattern.compile("([0-9][ ]?р(уб|\\.)|RUB [0-9])");
83+
84+
// Regular expression that matches Euro.
85+
private static final Pattern EUR_CURRENCY_REGEXP = Pattern.compile("€[0-9]");
8386

8487
// Regular expression that matches Ukrainian hryvnia.
8588
private static final Pattern UAH_CURRENCY_REGEXP = Pattern.compile("([0-9] |\\b)грн\\b");
@@ -505,6 +508,12 @@ public SeriesExtractedInfo extract(String pageUrl, RawParsedDataDto data) {
505508
return Currency.RUB.toString();
506509
}
507510

511+
matcher = EUR_CURRENCY_REGEXP.matcher(fragment);
512+
if (matcher.find()) {
513+
log.debug("Currency is EUR");
514+
return Currency.EUR.toString();
515+
}
516+
508517
matcher = UAH_CURRENCY_REGEXP.matcher(fragment);
509518
if (matcher.find()) {
510519
log.debug("Currency is UAH");

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
@@ -753,4 +753,13 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
753753
'US$16.50' | _
754754
}
755755

756+
@Unroll
757+
def 'extractCurrency() should extract EUR currency from "#fragment"'(String fragment) {
758+
expect:
759+
service.extractCurrency(fragment) == 'EUR'
760+
where:
761+
fragment | _
762+
'€3.50' | _
763+
}
764+
756765
}

0 commit comments

Comments
 (0)