Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |