Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 773 - new method "getProductNameBrandQuantity" #844

Merged
merged 6 commits into from
Feb 4, 2024

Conversation

monsieurtanuki
Copy link
Contributor

What

  • New method getProductNameBrandQuantity.
  • Added needed "abbreviated_product_name" product fields.

Fixes bug(s)

Impacted files

  • api_get_product_test.dart: tested "abbreviated product name" fields
  • product.dart: added method getProductNameBrandQuantity; added "abbreviated product name" fields
  • product.g.dart: generated
  • product_fields.dart: added "abbreviated product name" fields

Impacted files:
* `api_get_product_test.dart`: tested "abbreviated product name" fields
* `product.dart`: added method `getProductNameBrandQuantity`; added "abbreviated product name" fields
* `product.g.dart`: generated
* `product_fields.dart`: added "abbreviated product name" fields
@teolemon teolemon requested review from g123k and M123-dev December 15, 2023 12:15
/// Returns the best version of a product name.
///
/// cf. openfoodfacts-server/lib/ProductOpener/Products.pm
String getBestProductName(final OpenFoodFactsLanguage language) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to return a null value if there is no match; otherwise you force checking an empty string

@codecov-commenter
Copy link

codecov-commenter commented Jan 1, 2024

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (2c6ba80) 75.80% compared to head (79dc521) 75.64%.

Files Patch % Lines
lib/src/model/product.dart 19.23% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #844      +/-   ##
==========================================
- Coverage   75.80%   75.64%   -0.17%     
==========================================
  Files         224      224              
  Lines        7903     7941      +38     
==========================================
+ Hits         5991     6007      +16     
- Misses       1912     1934      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@monsieurtanuki
Copy link
Contributor Author

Closing as stale.

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all sorry for my very irregular contributions, bout to write my finals in April and Mai, guess especially this PR somehow got lost in the notifications.

Added a small comment, otherwise good. Especially the new bestName method could be great for outside package users

Comment on lines +978 to +995
if ((tmp = productNameInLanguages?[language])?.isNotEmpty == true) {
return tmp!;
}
if ((tmp = productName)?.isNotEmpty == true) {
return tmp!;
}
if ((tmp = genericNameInLanguages?[language])?.isNotEmpty == true) {
return tmp!;
}
if ((tmp = genericName)?.isNotEmpty == true) {
return tmp!;
}
if ((tmp = abbreviatedNameInLanguages?[language])?.isNotEmpty == true) {
return tmp!;
}
if ((tmp = abbreviatedName)?.isNotEmpty == true) {
return tmp!;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we do a

tmp ??= x;
tmp ??= y;

return tmp;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@M123-dev Looks tempting but we check "not null and not empty", not just "not null", therefore your suggestion would potentially return empty strings.

@monsieurtanuki monsieurtanuki reopened this Feb 4, 2024
@monsieurtanuki monsieurtanuki merged commit 2167bf9 into openfoodfacts:master Feb 4, 2024
5 of 6 checks passed
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your review, and good luck for your finals!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Add product_name_brand_quantity function
4 participants