-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add Faker::Commerce.rating #2808
Conversation
69f0fa7
to
85ab1f7
Compare
lib/faker/default/commerce.rb
Outdated
# Faker::Commerce.rating(range: 0..10.0, decimals: 2) #=> 8.92 | ||
# | ||
# @faker.version next | ||
def rating(range: 0..5.0, decimals: 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of adding a check here for the decimals to be within a reasonable limit? and checking if the decimals can't be negative?
lib/locales/en/commerce.yml
Outdated
@@ -8,7 +8,7 @@ en: | |||
product: [Chair, Car, Computer, Gloves, Pants, Shirt, Table, Shoes, Hat, Plate, Knife, Bottle, Coat, Lamp, Keyboard, Bag, Bench, Clock, Watch, Wallet] | |||
promotion_code: | |||
adjective: ['Amazing', 'Awesome', 'Cool', 'Good', 'Great', 'Incredible', 'Killer', 'Premium', 'Special', 'Stellar', 'Sweet'] | |||
noun: ['Code', 'Deal', 'Discount', 'Price', 'Promo', 'Promotion', 'Sale', 'Savings'] | |||
noun: ['Code', 'Deal', 'Discount', 'Price', 'Rating', 'Promo', 'Promotion', 'Sale', 'Savings'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have a Japanese commerce locale. Could you update that as well?
c6f6c10
to
3a46d5c
Compare
3a46d5c
to
d785886
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for submitting the changes @bradly
Could you add the following tests as well:
- Verify that
as_string
works with other arguments. For example:Faker::Commerce.rating(range: 0..10, decimals: 2, as_string: false)
returns a string for me. - Could you clarify more about the use case for
as_string
? Is that something the user can parse on their own if they need it? I'm a bit unsure we should have the responsibility of converting the Rating. - What do you think of adding upper limits to both
range
anddecimals
? People could enter high numbers for them, which would crash the generator. - Have you considered returning an
ArgumentError
for when the decimals are not positive? That way, the user can identify what the error is and fix it, then try again. If we just ignore it, they won't know what happened. We can also handlerange
anddecimals
asArgumentError
when they exceed the upper limit. What upper limits do you suggest for them?
Thanks!
hi @bradly are you still interested in working on this one? Thanks! |
Hi @bradly I will close this since it hasn't been active for a couple of months. Feel free to re-open and rebase with main if you're still planning on working on this. Thanks! |
Motivation / Background
This Pull Request has been created because I needed to generate ratings for a product.
Additional information
My use case was for a rating for a product so I put this in Fake::Commerce, but there are other generators that could have a ratings as well: App, Book, Game, Movie, Restaurant, etc..
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
If you're proposing a new generator: