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

add brand, vendor support to commerce (#1601) #1731

Merged
merged 6 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/default/commerce.md
Expand Up @@ -23,4 +23,10 @@ Faker::Commerce.promotion_code #=> "AmazingDeal829102"
Faker::Commerce.promotion_code(digits: 2) #=> "AmazingPrice57"

Faker::Commerce.material #=> "Plastic"

# Generate a random brand
Faker::Commerce.brand #=> "Apple"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice ! I will want to use this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!


# Generate a random vendor
Faker::Commerce.vendor #=> "Walmart"
```
28 changes: 28 additions & 0 deletions lib/faker/default/commerce.rb
Expand Up @@ -57,6 +57,34 @@ def price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.
price
end

##
# Produces a randomized string of a brand name
# @example
# Faker::Commerce.brand #=> 'Apple'
#
# @return [string]
#
# @faker.version next
#
##
def brand
ashishra0 marked this conversation as resolved.
Show resolved Hide resolved
fetch('commerce.brand')
end

##
# Produces a randomized string of a vendor name
# @example
# Faker::Commerce.vendor #=> 'Dollar General'
#
# @return [string]
#
# @faker.version next
#
##
def vendor
fetch('commerce.vendor')
end

private

def categories(num)
Expand Down
17 changes: 17 additions & 0 deletions lib/locales/en/commerce.yml
Expand Up @@ -9,3 +9,20 @@ en:
promotion_code:
adjective: ['Amazing', 'Awesome', 'Cool', 'Good', 'Great', 'Incredible', 'Killer', 'Premium', 'Special', 'Stellar', 'Sweet']
noun: ['Code', 'Deal', 'Discount', 'Price', 'Promo', 'Promotion', 'Sale', 'Savings']
brand: ['Samsung',
'Dell',
'Nike',
'Apple',
'LG',
'Adidas',
'Nikon',
'Sony',
'Beats',
'GoPro'
]
vendor: [
'Amazon',
'Dollar General',
'Walmart',
'Target'
]
8 changes: 8 additions & 0 deletions test/faker/default/test_faker_commerce.rb
Expand Up @@ -95,4 +95,12 @@ def test_when_as_string_is_true
assert @tester.price(range: 0..100.0, as_string: true).is_a?(String)
assert @tester.price(range: 100..500.0, as_string: true).include?('.')
end

def test_brand
assert @tester.brand.match(/[A-Z][a-z]+\.?/)
end

def test_vendor
assert @tester.vendor.match(/[A-Z][a-z]+\.?/)
end
end