Skip to content

Commit

Permalink
Add Allergens to Food (#2706)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRustad committed Feb 13, 2023
1 parent e669b18 commit 01e4c1e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/default/food.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Available since version 1.7.0.

```ruby
Faker::Food.allergen #=> "Peanuts"

Faker::Food.description #=> "Three eggs with cilantro, tomatoes, onions, avocados and melted Emmental cheese. With a side of roasted potatoes, and your choice of toast or croissant."

Faker::Food.dish #=> "Caesar Salad"
Expand Down
13 changes: 13 additions & 0 deletions lib/faker/default/food.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ class Food < Base
flexible :food

class << self
##
# Retrieves an allergen.
#
# @return [String]
#
# @example
# Faker::Food.allergen #=> "Peanuts"
#
# @faker.version next
def allergen
fetch('food.allergens')
end

##
# Retrieves a typical dish from each country.
#
Expand Down
12 changes: 12 additions & 0 deletions lib/locales/en/food.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
en:
faker:
food:
allergens:
- Eggs
- Milk
- Mustard
- Peanuts
- Crustaceans and molluscs
- Fish
- Sesame seeds
- Soy
- Sulphites
- Tree Nuts
- Wheat and triticale
dish:
- Arepas
- Barbecue Ribs
Expand Down
4 changes: 4 additions & 0 deletions test/faker/default/test_faker_food.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def test_flexible_key
assert_equal(:food, @tester.flexible_key)
end

def test_allergen
assert_match(/\w+/, @tester.allergen)
end

def test_dish
assert_match(/\w+/, @tester.dish)
end
Expand Down

0 comments on commit 01e4c1e

Please sign in to comment.