Skip to content

Commit

Permalink
add brand, vendor support to commerce (#1601) (#1731)
Browse files Browse the repository at this point in the history
* add brands and vendors to commerce

* add YARD docs for brand and vendor

* modified to list

* add brands and vendors to commerce

* modified to list
  • Loading branch information
ashishra0 committed Aug 19, 2021
1 parent 4e4acaf commit 45bdf35
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/default/commerce.md
Expand Up @@ -21,4 +21,12 @@ Faker::Commerce.price(range: 0..10.0, as_string: true) #=> "2.18"
# Keyword arguments: digits
Faker::Commerce.promotion_code #=> "AmazingDeal829102"
Faker::Commerce.promotion_code(digits: 2) #=> "AmazingPrice57"

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

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

# Generate a random vendor
Faker::Commerce.vendor #=> "Walmart"
```
28 changes: 28 additions & 0 deletions lib/faker/default/commerce.rb
Expand Up @@ -126,6 +126,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
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

0 comments on commit 45bdf35

Please sign in to comment.