From 0361064e1274c4d2ec3546ee67ed9d9af43e6948 Mon Sep 17 00:00:00 2001 From: Eli Sadoff Date: Sat, 7 Nov 2020 14:48:25 -0500 Subject: [PATCH 1/4] Add tea --- lib/faker/default/tea.rb | 39 ++++++ lib/locales/en/tea.yml | 172 +++++++++++++++++++++++++++ test/faker/default/test_faker_tea.rb | 31 +++++ 3 files changed, 242 insertions(+) create mode 100644 lib/faker/default/tea.rb create mode 100644 lib/locales/en/tea.yml create mode 100644 test/faker/default/test_faker_tea.rb diff --git a/lib/faker/default/tea.rb b/lib/faker/default/tea.rb new file mode 100644 index 0000000000..dd2186d83a --- /dev/null +++ b/lib/faker/default/tea.rb @@ -0,0 +1,39 @@ +# 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" + 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.blend + # #=> "Green" + def type + fetch 'tea.type' + end + end + end +end diff --git a/lib/locales/en/tea.yml b/lib/locales/en/tea.yml new file mode 100644 index 0000000000..4de0891f9a --- /dev/null +++ b/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 diff --git a/test/faker/default/test_faker_tea.rb b/test/faker/default/test_faker_tea.rb new file mode 100644 index 0000000000..93b0ced6fd --- /dev/null +++ b/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.to_h do |type| + [type, Faker::Base.fetch_all("tea.variety.#{type.downcase}")] + end + @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 From 3a8884b02ade24aea83d5dae3d4b2efe8914c043 Mon Sep 17 00:00:00 2001 From: Eli Sadoff Date: Sat, 7 Nov 2020 14:54:53 -0500 Subject: [PATCH 2/4] Change #to_h with block to #map(block).to_h for Ruby 2.5 --- test/faker/default/test_faker_tea.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/faker/default/test_faker_tea.rb b/test/faker/default/test_faker_tea.rb index 93b0ced6fd..1e2e6cc36f 100644 --- a/test/faker/default/test_faker_tea.rb +++ b/test/faker/default/test_faker_tea.rb @@ -6,9 +6,9 @@ class TestFakerTea < Test::Unit::TestCase def setup @tester = Faker::Tea @types = Faker::Base.fetch_all('tea.type') - @varieties_by_type = @types.to_h do |type| + @varieties_by_type = @types.map do |type| [type, Faker::Base.fetch_all("tea.variety.#{type.downcase}")] - end + end.to_h @varieties = @varieties_by_type.values.flatten end From f2d171d58949051a142f0da296085b8511fd1f7e Mon Sep 17 00:00:00 2001 From: Eli Sadoff <9064062+snood1205@users.noreply.github.com> Date: Sun, 18 Apr 2021 16:36:17 -0400 Subject: [PATCH 3/4] Apply code review suggestions per @koic --- lib/faker/default/tea.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/faker/default/tea.rb b/lib/faker/default/tea.rb index dd2186d83a..00d681c9f3 100644 --- a/lib/faker/default/tea.rb +++ b/lib/faker/default/tea.rb @@ -6,7 +6,7 @@ class Tea < Base class << self ## - # Produces a random variety or blend of tea + # 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 @@ -18,19 +18,21 @@ class << self # @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 + # Produces a random type of tea. # # @return [String] a type of tea # # @example # Faker::Tea.blend # #=> "Green" + # @faker.version next def type fetch 'tea.type' end From 5b6d518c67f130a559f6bcb3102d4a1b47205fd4 Mon Sep 17 00:00:00 2001 From: Eli Sadoff <9064062+snood1205@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:05:24 -0400 Subject: [PATCH 4/4] More PR adjustments --- README.md | 1 + doc/default/tea.md | 15 +++++++++++++++ lib/faker/default/tea.rb | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 doc/default/tea.md diff --git a/README.md b/README.md index ca857bbf5a..14ffb34750 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/doc/default/tea.md b/doc/default/tea.md new file mode 100644 index 0000000000..bb88784f5e --- /dev/null +++ b/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" +``` diff --git a/lib/faker/default/tea.rb b/lib/faker/default/tea.rb index 00d681c9f3..006b26e0f1 100644 --- a/lib/faker/default/tea.rb +++ b/lib/faker/default/tea.rb @@ -30,7 +30,7 @@ def variety(type: nil) # @return [String] a type of tea # # @example - # Faker::Tea.blend + # Faker::Tea.type # #=> "Green" # @faker.version next def type