Skip to content

Commit

Permalink
adding vermouth (martini)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Aug 5, 2021
1 parent 7488e9d commit 8557a0c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class AlcoholController(
Other to listOf(
"(?<!\\\\s)узо", "\\s+мента", "мента\\s+",
"ликьор", "^ром\\s+", "\\s+ром\\s+", "\\s+ром\$", "текила", "бренди", "коняк", "абсент",
"(?<!вър)джин(?!джи)", "Пастис", "анасон.*напитк", "мастика", "сайдер", "somersby"
"(?<!вър)джин(?!джи)", "Пастис", "анасон.*напитк", "мастика", "сайдер", "somersby",
"вермут", "martini", "мартини"
)
).mapValues {
it.value.map { regex ->
Expand Down Expand Up @@ -94,7 +95,7 @@ class AlcoholController(
product.name.contains(entry.value)
}?.key
if (isNull(maybeCategory)) {
alcoholProductOrNull(product)
alcoholProductOrNull(product, defaultCategory = Other)
} else {
product.copy(category = maybeCategory?.name)
}
Expand Down Expand Up @@ -160,14 +161,16 @@ class AlcoholController(

}

private fun alcoholProductOrNull(product: Product): Product? {
private fun alcoholProductOrNull(product: Product, defaultCategory: AlcoholCategory? = null): Product? {
val maybeCategory = alcoholCategoryResolvers.entries.firstOrNull { categoryResolver ->
categoryResolver.value.any { regex ->
product.name.contains(regex)
}
}?.key
return if (isNull(maybeCategory)) {
null
defaultCategory?.let {
product.copy(category = it.name)
}
} else {
product.copy(category = maybeCategory?.name)
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/api/alcohol/expected-cdn.json
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,14 @@
"oldPrice": null,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/44212/menta-karnobat-200ml-image_5f9b5939ac52a_600x600.jpeg?1604016458"
},
{
"name": "Вермут MARTINI Bianco 15%",
"quantity": "1 л",
"price": 18.89,
"oldPrice": 21.49,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/39261/vermut-martini-bianco-15--1-l-image_5ea2c90ac4231_300x300.png?1587731331"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/api/alcohol/expected-with-duplicates.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,14 @@
"oldPrice": null,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/44212/menta-karnobat-200ml-image_5f9b5939ac52a_600x600.jpeg?1604016458"
},
{
"name": "Вермут MARTINI Bianco 15%",
"quantity": "1 л",
"price": 18.89,
"oldPrice": 21.49,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/39261/vermut-martini-bianco-15--1-l-image_5ea2c90ac4231_300x300.png?1587731331"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/api/alcohol/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,14 @@
"oldPrice": null,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/44212/menta-karnobat-200ml-image_5f9b5939ac52a_600x600.jpeg?1604016458"
},
{
"name": "Вермут MARTINI Bianco 15%",
"quantity": "1 л",
"price": 18.89,
"oldPrice": 21.49,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/39261/vermut-martini-bianco-15--1-l-image_5ea2c90ac4231_300x300.png?1587731331"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/api/alcohol/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,14 @@
"oldPrice": null,
"category": "Високоалкохолни напитки",
"picUrl": "https://cdncloudcart.com/16398/products/images/44212/menta-karnobat-200ml-image_5f9b5939ac52a_600x600.jpeg?1604016458"
},
{
"name": "Вермут MARTINI Bianco 15%",
"quantity": "1 л",
"price": 18.89,
"oldPrice": 21.49,
"category": "Високоалкохолни напитки",
"picUrl": "https://cdncloudcart.com/16398/products/images/39261/vermut-martini-bianco-15--1-l-image_5ea2c90ac4231_300x300.png?1587731331"
}
]
},
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/api/flat/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,17 @@
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/44212/menta-karnobat-200ml-image_5f9b5939ac52a_600x600.jpeg?1604016458"
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Вермут MARTINI Bianco 15%",
"quantity": "1 л",
"price": 18.89,
"oldPrice": 21.49,
"discount" : 12,
"category": "Other",
"picUrl": "https://cdncloudcart.com/16398/products/images/39261/vermut-martini-bianco-15--1-l-image_5ea2c90ac4231_300x300.png?1587731331"
},
{
"supermarket": "Fantastico",
"logo": "http://fantastico.bg",
Expand Down

0 comments on commit 8557a0c

Please sign in to comment.