Skip to content

Commit

Permalink
Add Faker::Tea (#2190)
Browse files Browse the repository at this point in the history
* Add tea

* Change #to_h with block to #map(block).to_h for Ruby 2.5

* Apply code review suggestions per @koic

* More PR adjustments
  • Loading branch information
snood1205 committed Apr 20, 2021
1 parent afd7680 commit 9e47c3a
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -207,6 +207,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'mast
- [Faker::Stripe](doc/default/stripe.md)
- [Faker::Subscription](doc/default/subscription.md)
- [Faker::Superhero](doc/default/superhero.md)
- [Faker::Tea](doc/default/tea.md)
- [Faker::Team](doc/default/team.md)
- [Faker::Time](doc/default/time.md)
- [Faker::Twitter](doc/default/twitter.md)
Expand Down
15 changes: 15 additions & 0 deletions doc/default/tea.md
@@ -0,0 +1,15 @@
# Faker::Tea

Available since version next.

```ruby
# Get a tea variety
Faker::Tea.variety # => "Earl Grey"

# Get a tea variety, by type of tea. Accepted types:
# ['Black', 'Green', 'Herbal', 'Oolong', 'White']
Faker::Tea.variety(type: 'Green') #=> "Jasmine"

# Get a type of tea
Faker::Tea.type #=> "Herbal"
```
41 changes: 41 additions & 0 deletions lib/faker/default/tea.rb
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module Faker
class Tea < Base
flexible :tea

class << self
##
# Produces a random variety or blend of tea.
#
# @param type [String, nil] the type of tea to query for (valid types: 'Black', 'Green', 'Oolong', 'White', and 'Herbal')
# @return [String] a variety of tea
#
# @example
# Faker::Tea.variety
# #=> "Earl Grey"
#
# @example
# Faker::Tea.variety(type: 'Green')
# #=> "Jasmine"
# @faker.version next
def variety(type: nil)
type ||= fetch('tea.type')
fetch "tea.variety.#{type.downcase}"
end

##
# Produces a random type of tea.
#
# @return [String] a type of tea
#
# @example
# Faker::Tea.type
# #=> "Green"
# @faker.version next
def type
fetch 'tea.type'
end
end
end
end
172 changes: 172 additions & 0 deletions lib/locales/en/tea.yml
@@ -0,0 +1,172 @@
en:
faker:
tea:
variety:
black:
- Assam
- Ceylon
- Congou
- Darjeeling
- Dianhong
- Earl Grey
- English Afternoon
- English Breakfast
- Irish Breakfast
- Jaekseol
- Jiu Qu Hong Mei
- Kangra
- Keemun
- Lady Grey
- Lahijan
- Lapsang Souchong
- Masala Chai
- Munnar
- Nepali
- Nilgiri
- Rize
- Scottish Breakfast
- Sun Moon Lake
- Yingdehong
oolong:
- Alishan
- Bai Jiguan
- Da Hong Pao
- Dancong
- Dongding
- Dongfang Meiren
- Fujian
- Gaoshan
- Huangjin Gui
- Ji Xuan
- Lishan
- Pouchong
- Rougui
- Ruan Zhi
- Shui Jin Gui
- Shui Xian
- Tieguanyin
- Tieluohan
- Tienguanyin
- Vietnamese
green:
- Bancha
- Biluochun
- Chun Mee
- Daejak
- Garucha
- Genmaicha
- Gunpowder
- Gyokuro
- Hojicha
- Huangshan Maofeng
- Ipcha
- Jungjak
- Kabusecha
- Kukicha
- Longjing
- Lu'an Melon Seed
- Matcha
- Sejak
- Sencha
- Shincha
- Taipin Houkui
- Ujeon
- Xinyang Maojian
white:
- Bai Mu Dan
- Fujian New Craft
- Gongmei
- Shou Mei
- Yi Zhen Bai Hao
herbal:
- Anise
- Asiatic Penny-Wort
- Bael Fruit
- Barley
- Bee Balm
- Boldo
- Burdock
- Cacao
- Caraway
- Cat's Claw
- Catnip
- Cerasse
- Chamomile
- Che Dang
- Chinese Knot-Weed
- Chrysanthemum
- Cinnamon
- Citrus Peel
- Dandelion
- Dill
- Dried Lime
- Echinacea
- Elderberry
- Essiac
- European Mistletoe
- Fennel
- Gentian
- Ginger Root
- Ginseng
- Goji
- Hawthorn
- Hibiscus
- Honeybush
- Horehound
- Houttuynia
- Jiaogulan
- Kapor
- Kuzuyu
- Labrador
- Lemon Balm
- Lemon Ginger
- Lemon Grass
- Licorice Root
- Lime Blossom
- Luo Han Guo
- Mint
- Moringa
- Mountain Tea
- Neem
- Nettle
- New Jersey Tea
- Noni
- Oksusu Cha
- Olive Leaf
- Osmanthus
- Pandan
- Patchouli
- Pine
- Qishr
- Red Clover
- Red Raspberry
- Roasted Wheat
- Rooibos
- Rose Hip
- Roselle
- Rosemary
- Sage
- Sagebrush
- Serendib
- Skurayu
- Sobacha
- Spearmint
- Spicebush
- Spruce
- St. John's Wort
- Thyme
- Tulsi
- Turmeric
- Valerian
- Verbena
- Vetiver
- Wax Gourd
- Wong Lo Kat
- Woodruff
- Yarrow
type:
- Black
- Oolong
- Green
- White
- Herbal
31 changes: 31 additions & 0 deletions test/faker/default/test_faker_tea.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerTea < Test::Unit::TestCase
def setup
@tester = Faker::Tea
@types = Faker::Base.fetch_all('tea.type')
@varieties_by_type = @types.map do |type|
[type, Faker::Base.fetch_all("tea.variety.#{type.downcase}")]
end.to_h
@varieties = @varieties_by_type.values.flatten
end

def test_variety
assert(@varieties.all? do |variety|
variety.match?(/^(?:[A-Z]['.\-a-z]+[\s-])*(?:[A-Z]['.\-a-z]+)$/)
end)
assert @varieties.include?(@tester.variety)
end

def test_variety_with_argument
@types.each do |type|
assert @varieties_by_type[type].include?(@tester.variety(type: type))
end
end

def test_types
assert @types.all? { |type| type.match?(/^[A-Z][a-z]+$/) }
end
end

0 comments on commit 9e47c3a

Please sign in to comment.