Skip to content

Commit a48f8d7

Browse files
committed
Series import: extract release year from "2015г" string.
1 parent 1e98f60 commit a48f8d7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/ru/mystamps/web/service/SeriesInfoExtractorServiceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class SeriesInfoExtractorServiceImpl implements SeriesInfoExtractorServic
4747

4848
// Regular expression matches release year of the stamps (from 1840 till 2099).
4949
private static final Pattern RELEASE_YEAR_REGEXP =
50-
Pattern.compile("18[4-9][0-9]|19[0-9]{2}|20[0-9]{2}");
50+
Pattern.compile("(18[4-9][0-9]|19[0-9]{2}|20[0-9]{2})г?");
5151

5252
// Regular expression matches number of the stamps in a series (from 1 to 99).
5353
private static final Pattern NUMBER_OF_STAMPS_REGEXP = Pattern.compile(
@@ -183,12 +183,13 @@ protected Integer extractReleaseYear(String fragment) {
183183

184184
String[] candidates = StringUtils.split(fragment);
185185
for (String candidate : candidates) {
186-
if (!RELEASE_YEAR_REGEXP.matcher(candidate).matches()) {
186+
Matcher matcher = RELEASE_YEAR_REGEXP.matcher(candidate);
187+
if (!matcher.matches()) {
187188
continue;
188189
}
189190

190191
try {
191-
Integer year = Integer.valueOf(candidate);
192+
Integer year = Integer.valueOf(matcher.group(1));
192193
log.debug("Release year is {}", year);
193194
return year;
194195

src/test/groovy/ru/mystamps/web/service/SeriesInfoExtractorServiceImplTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
239239
'2010\t\tbrazil' | _
240240
'2010 brazil' | _
241241
'prehistoric animals 2010 congo' | _
242+
'2010г' | _
242243
}
243244

244245
@SuppressWarnings('UnnecessaryGetter')

0 commit comments

Comments
 (0)