Skip to content

Commit

Permalink
Faker::Coffee (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjh authored and stympy committed Mar 18, 2017
1 parent baf7f82 commit 2825578
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/coffee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Faker::Coffee

```ruby
Faker::Coffee.blend_name #=> "Summer Solstice"

Faker::Coffee.origin #=> "Antigua, Guatemala"

Faker::Coffee.variety #=> "Pacas"

Faker::Coffee.notes #=> "balanced, silky, marzipan, orange-creamsicle, bergamot"
```
29 changes: 29 additions & 0 deletions lib/faker/coffee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Faker
class Coffee < Base
class << self
def blend_name
parse('coffee.blend_name')
end

def origin
country = fetch('coffee.country')
region = fetch("coffee.regions.#{search_format(country)}")
"#{region}, #{country}"
end

def variety
fetch('coffee.variety')
end

def notes
parse('coffee.notes')
end

private

def search_format(key)
key.split.length > 1 ? key.split.join('_').downcase : key.downcase
end
end
end
end
29 changes: 29 additions & 0 deletions lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,35 @@ en:
"Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so therefore Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only.",
"Sometimes people jot down pseudo-code on paper. If that pseudo-code runs directly on their computers, its best, isn't it? Ruby tries to be like that, like pseudo-code that runs. Python people say that too."
]
coffee:
country: ["Brazil", "Colombia", "Sumatra", "Ethiopia", "Honduras", "Kenya", "Uganda", "Mexico", "Guatemala", "Nicaragua", "Costa Rica", "Tanzania", "El Salvador", "Rwanda", "Burundi", "Panama", "Yemen", "India"]
regions:
brazil: ["Sul Minas", "Mogiana", "Cerrado"]
colombia: ["Nariño", "Huila", "Tolima", "Cauca", "Casanare", "Santander", "Antioquia", "Cundinamarca", "Boyacá"]
sumatra: ["Tapanuli", "Lintong", "Aceh", "Lake Tawar", "Lintong", "Gayo"]
ethiopia: ["Sidama", "Harrar", "Limu", "Ojimmah", "Lekempti", "Wellega", "Gimbi"]
honduras: ["Agalta", "Comayagua", "Copan", "Montecillos", "Opalca", "El Paraiso"]
kenya: ["Bungoma", "Embu", "Kiamba", "Kirinyaga", "Mt. Kenya", "Kisii", "Meru", "Murang'a", "Machakos", "Thika", "Nyeri", "Nakuru", "Nyanza", "Kericho"]
uganda: ["Bugisu", "Mount Elgon", "Kibale"]
mexico: ["Chiapas", "Oaxaca", "Veracruz", "Colima", "San Luis Potosi", "Nayarit", "Hidalgo", "Puebla", "Jalisco"]
guatemala: ["Acatenango", "Antigua", "Atitlan", "Fraijanes", "Huehuetenango", "Nuevo Oriente", "Coban", "San Marcos"]
nicaragua: ["Matagalpa", "Jinotega", "Boaco", "Madriz", "Nueva Segovia", "Estelí", "Dipilto", "Jalapa", "Carazo", "Granada", "Masaya", "Managua", "Rivas"]
costa_rica: ["Tarrazu", "Central Valley", "West Valley", "Guanacaste", "Tres Rios", "Turrialba", "Orosi", "Brunca"]
tanzania: ["Western Region, Bukova", "Western Region, Kigoma", "Mbeya Region", "Southern Region, Mbinga", "Western Region, Tarime", "Northern Region, Oldeani", "Northern Region, Arusha", "Northern Region, Kilimanjaro", "Southern Region, Morogoro"]
el_salvador: ["Alotepec-Metapán", "Apaneca-Ilamatepec", "El Balsamo-Quetzaltepec", "Cacahuatique", "Chichontepec", "Tecapa-Chinameca"]
rwanda: ["Rulindo", "Gishamwana Coffee Island", "Lake Kivu Region", "Kigeyo Washing Station", "Kabirizi"]
burundi: ["Kayanza"]
panama: ["Boquete", "Chiriqui", "Volcan"]
yemen: ["Mattari", "San'ani", "Hirazi", "Raimi"]
india: ["Chikmagalur", "Coorg","Biligiris", "Bababudangiris", "Manjarabad", "Nilgiris", "Travancore", "Manjarabad", "Brahmaputra", "Pulneys", "Sheveroys"]
variety: ["Liberica", "S288", "S795", "Kent", "Java", "Dilla", "Sumatara", "Catuai", "Pacamara", "Mundo Novo", "Red Bourbon", "Bourbon", "Yellow Bourbon", "Pacas", "Caturra", "Pink Bourbon", "Colombia", "Obata", "Catimors", "Sarchimor", "Mokka", "Kaffa", "Gimma", "Tafari-Kela", "S.4", "Agaro", "Dega", "Barbuk Sudan", "Ennarea", "Geisha", "Gesha", "Blue Mountain", "Kona", "San Ramon", "SL28", "SL34", "Villa Sarchi", "Villalobos", "Typica", "Ethiopian Heirloom"]
intensifier: ["muted", "dull", "mild", "structured", "balanced", "rounded", "soft", "faint", "delicate", "dry", "astringent", "quick", "clean", "crisp", "bright", "vibrant", "tart", "wild", "unbalanced", "sharp", "pointed", "dense", "deep", "complex", "juicy", "lingering", "dirty"]
body: ["watery", "tea-like", "silky", "slick", "juicy", "smooth", "syrupy", "round", "creamy", "full", "velvety", "big", "chewy", "coating"]
descriptor: ["bergamot", "hops", "black-tea", "green-tea", "mint", "sage", "dill", "grassy", "snow pea", "sweet pea", "mushroom", "squash", "green pepper", "olive", "leafy greens", "hay", "tobacco", "cedar", "fresh wood", "soil", "tomato", "sundried tomato", "soy sauce", "leathery", "clove", "liquorice", "curry", "nutmeg", "ginger", "corriander", "cinnamon", "white pepper", "black pepper", "carbon", "smokey", "burnt sugar", "toast", "fresh bread", "barley", "wheat", "rye", "graham cracker", "granola", "almond", "hazelnut", "pecan", "cashew", "peanut", "walnut", "cola", "molasses", "maple syrup", "carmel", "brown sugar", "sugar cane", "marshmallow", "cream", "butter", "honey", "nougat", "vanilla", "milk chocolate", "cocoa powder", "bittersweet chocolate", "bakers chocolate", "cacao nibs", "prune", "dates", "figs", "raisin", "golden raisin", "black currant", "red currant", "blueberry", "strawberry", "raspberry", "cranberry", "black cherry", "cherry", "plum", "apricot", "nectarine", "peach", "coconut", "banana", "kiwi", "mango", "papaya", "pineapple", "passion fruit", "tamarind", "star fruit", "lychee", "concord grape", "red grape", "green grape", "white grape", "cantaloupe", "honeydew", "watermelon", "red apple", "green apple", "orange", "mandarin", "tangerine", "clementine", "grapefruit", "lime", "meyer lemon", "lemonade", "lemon", "orange creamsicle", "marzipan", "nutella", "lemongrass", "orange blossom", "jasmine", "honeysuckle", "magnolia", "lavender", "rose hips", "hibiscus", "lemon verbena", "medicinal", "quakery", "baggy", "potato defect!", "musty", "rubber"]
notes: "#{intensifier}, #{body}, #{descriptor}, #{descriptor}, #{descriptor}"
name_1: ["Summer", "Holiday", "Jacked", "Joe", "Express", "Reg's", "Split", "Spilt", "Chocolate", "Dark", "Veranda", "Major", "Bluebery", "American", "Huggy", "Wake-up", "Morning", "Evening", "Winter", "Captain's", "Thanksgiving", "Seattle", "Brooklyn", "Café", "Blacktop", "Pumpkin-spice", "Good-morning", "Postmodern", "The Captain's", "The", "Cascara", "Melty", "Heart", "Goodbye", "Hello", "Street", "Red", "Blue", "Green", "Strong", "KrebStar", "Kreb-Full-o"]
name_2: ["Solstice", "Blend", "Level", "Enlightenment", "Cowboy", "", "Choice", "Select", "Equinox", "Star", "Forrester", "Java", "Symphony", "Utopia", "Cup", "Mug", "Been", "Bean", "Cake", "Extract", "Delight", "Pie", "America", "Treat", "Volcano", "Breaker", "Town", "Light", "Look", "Coffee", "Nuts"]
blend_name: "#{name_1} #{name_2}"
dragon_ball:
characters: ["Goku", "Bulma", "Kami", "Yamcha", "Krillin", "Tien", "Piccolo", "Gohan", "Vegeta", "Kid Trunks", "Goten", "Future Trunks", "Pan", "Android 18", "Android 16", "Android 17", "Android 19", "Android 20", "Beerus", "Chaozu", "Chi-Chi", "Launch", "Mr. Satan", "Oolong", "Puar", "Videl", "Whis", "Yajirobe", "Demon King Piccolo", "Freeza", "Cell", "Majin Buu", "Goku Black", "Zamasu", "Baba", "Bra", "Bardock", "Champa", "Dende", "Dr. Gero", "Captain Ginyu", "Grandpa Gohan", "Jaco", "King Kai", "Supreme Kai", "Elder Kai", "Mr. Popo", "Nappa", "Uub", "Pilaf", "Raditz", "Shenron", "Vados", "Zarbon", "Broly", "Cooler", "King Cold", "Garlic Jr", "King Vegeta", "Nail", "Guru", "Hit", "Super Saiyan Goku", "Super Saiyan 2 Goku", "Super Saiyan 3 Goku", "Super Saiyan Vegeta", "Super Saiyan 2 Vegeta", "Majin Vegeta", "Super Saiyan Gohan", "Super Saiyan 2 Gohan", "Super Saiyan Goten", "Super Saiyan Trunks", "Vegito", "Gogeta", "Super Saiyan Blue Goku", "Super Saiyan Blue Vegeta", "Mystic Gohan"]
rupaul:
Expand Down
52 changes: 52 additions & 0 deletions test/test_faker_coffee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')

class TestFakerCoffee < Test::Unit::TestCase
def setup
@tester = Faker::Coffee
@countries = Faker::Base.fetch_all('coffee.country')
@intensifiers = Faker::Base.fetch_all('coffee.intensifier')
@body_descriptors = Faker::Base.fetch_all('coffee.body')
@flavor_descriptors = Faker::Base.fetch_all('coffee.descriptor')
@varieties = Faker::Base.fetch_all('coffee.variety')
blend_name_words_one = Faker::Base.fetch_all('coffee.name_1')
blend_name_words_two = Faker::Base.fetch_all('coffee.name_2')
@name_words = blend_name_words_one.concat(blend_name_words_two)
end

def test_origin
assert origin = @tester.origin.match(/\A(?<region>([[:alnum:]]+'?-?.?,?\s?){1,5}), (?<country>([[:alnum:]]+\s?){1,5})\z/)

region, country = origin[:region], origin[:country]
search_format_country = country.split.length > 1 ? country.downcase.split.join('_') : country.downcase
regions = Faker::Base.fetch_all("coffee.regions.#{search_format_country}")

assert @countries.include?(country)
assert regions.include?(region)
end

def test_notes
assert notes = @tester.notes
.match(/\A(?<intensifier>[\s\w-]+), (?<body>[\s\w-]+), (?<f1>[!\s\w-]+), (?<f2>[!\s\w-]+), (?<f3>[!\s\w-]+)\z/)

assert @intensifiers.include?(notes[:intensifier])
assert @body_descriptors.include?(notes[:body])

[notes[:f1], notes[:f2], notes[:f3]].each do |flavor|
assert @flavor_descriptors.include?(flavor)
end
end

def test_variety
assert @tester.variety.match(/\w+\.?/)

assert @varieties.include?(@tester.variety)
end

def test_blend_name
assert blend = @tester.blend_name.match(/(([[:alnum:]]+(-?\w*)*('?\w+)?) ?){1,}/)

blend[0].split.each do |word|
assert @name_words.include?(word)
end
end
end

0 comments on commit 2825578

Please sign in to comment.