diff --git a/README.md b/README.md index c2ea1ede00..85eb73a5dd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Contents - [Faker::Company](doc/company.md) - [Faker::Crypto](doc/crypto.md) - [Faker::Date](doc/date.md) + - [Faker::Demographic](doc/demographic.md) - [Faker::Educator](doc/educator.md) - [Faker::File](doc/file.md) - [Faker::Fillmurray](doc/fillmurray.md) diff --git a/doc/demographic.md b/doc/demographic.md new file mode 100644 index 0000000000..36285fa2be --- /dev/null +++ b/doc/demographic.md @@ -0,0 +1,17 @@ +# Faker::Demographic + +```ruby +Faker::Demographic.race #=> "Native Hawaiian or Other Pacific Islander" + +Faker::Demographic.educational_attainment #=> "GED or alternative credential" + +Faker::Demographic.demonym #=> "Panamanian" + +Faker::Demographic.marital_status #=> "Widowed" + +Faker::Demographic.sex #=> "Female" + +Faker::Demographic.height #=> "1.61" + +Faker::Demographic.height(:imperial) #=> "6 ft, 2 in" +``` diff --git a/lib/faker.rb b/lib/faker.rb index 806dd32281..02f4a7067f 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -244,6 +244,7 @@ def unique(max_retries = 10_000) require 'faker/rock_band' require 'faker/fillmurray' require 'faker/job' +require 'faker/demographic' require 'extensions/array' require 'extensions/symbol' diff --git a/lib/faker/demographic.rb b/lib/faker/demographic.rb new file mode 100644 index 0000000000..666a940e01 --- /dev/null +++ b/lib/faker/demographic.rb @@ -0,0 +1,35 @@ +module Faker + class Demographic < Base + class << self + def race + fetch('demographic.race') + end + + def educational_attainment + fetch('demographic.educational_attainment') + end + + def demonym + fetch('demographic.demonym') + end + + def marital_status + fetch('demographic.marital_status') + end + + def sex + fetch('demographic.sex') + end + + def height(unit = :metric) + case unit + when :imperial + inches = rand_in_range(57, 86) + return "#{inches / 12} ft, #{inches % 12} in" + when :metric + return rand_in_range(1.45, 2.13).round(2).to_s + end + end + end + end +end diff --git a/lib/locales/en.yml b/lib/locales/en.yml index 7f16ba3acd..32219d0495 100755 --- a/lib/locales/en.yml +++ b/lib/locales/en.yml @@ -357,7 +357,7 @@ en: company: ['SpaceX', 'Blue Origin', 'Virgin Galactic', 'SpaceDev', 'Bigelow Aerospace', 'Orbital Sciences', 'JPL', 'NASA Jet Propulsion Laboratory'] distance_measurement: ['light years', 'AU', 'parsecs', 'kiloparsecs', 'megaparsecs'] meteorite: ['Aarhus', 'Abee', 'Adelie Land', 'Adhi Kot', 'Adzhi-Bogdo', 'Santa Rosa de Viterbo', 'Agen', 'Akbarpur', 'Albareto', 'Allan Hills 84001', 'Allan Hills A81005', 'Allegan', 'Allende', 'Ambapur Nagla', 'Andura', 'Angers', 'Angra dos Reis', 'Ankober', 'Anlong', 'Annaheim', 'Appley Bridge', 'Arbol Solo', 'Archie', 'Arroyo Aguiar', 'Assisi', 'Atoka', 'Avanhandava', 'Bacubirito', 'Baszkówka','Beardsley', 'Bellsbank', 'Bench Crater', 'Benton', 'Białystok', 'Blithfield','Block Island', 'Bovedy', 'Brachina', 'Brahin', 'Brenham', 'Buzzard Coulee','Campo del Cielo', 'Canyon Diablo', 'Cape York', 'Carancas', 'Chambord','Chassigny', 'Chelyabinsk', 'Chergach', 'Chinga', 'Chinguetti', 'Claxton','Coahuila', 'Cranbourne', 'D''Orbigny', 'Dronino', 'Eagle Station', 'Elbogen','Ensisheim', 'Esquel', 'Fukang', 'Gancedo', 'Gao–Guenie', 'Gay Gulch', 'Gebel Kamil', 'Gibeon', 'Goose Lake', 'Grant', 'Hadley Rille', 'Heat Shield Rock','Hoba', 'Homestead', 'Hraschina', 'Huckitta', 'Imilac', 'Itqiy', 'Kaidun','Kainsaz', 'Karoonda', 'Kesen', 'Krasnojarsk', 'L''Aigle', 'Lac Dodon', 'Lake Murray', 'Loreto', 'Los Angeles', 'Łowicz', 'Mackinac Island', 'Mbozi','Middlesbrough', 'Millbillillie', 'Mineo', 'Monte Milone', 'Moss','Mundrabilla', 'Muonionalusta', 'Murchison', 'Nakhla', 'Nantan','Neuschwanstein', 'Northwest Africa 7034', 'Northwest Africa 7325', 'Norton County', 'Novato', 'Northwest Africa 3009', 'Oileán Ruaidh (Martian)', 'Old Woman', 'Oldenburg', 'Omolon', 'Orgueil', 'Ornans', 'Osseo', 'Österplana 065','Ourique', 'Pallasovka', 'Paragould', 'Park Forest', 'Pavlovka', 'Peace River','Peekskill', 'Penouille', 'Polonnaruwa', 'High Possil', 'Příbram', 'Pultusk','Qidong', 'Richardton', 'Santa Vitoria do Palmar', 'Sayh al Uhaymir 169','Seymchan', 'Shelter Island', 'Shergotty', 'Sikhote-Alin', 'Sołtmany','Springwater', 'St-Robert', 'Stannern', 'Sulagiri', 'Sutter''s Mill','Sylacauga', 'Tagish Lake', 'Tamdakht', 'Tenham', 'Texas Fireball', 'Tissint','Tlacotepec', 'Toluca', 'Treysa', 'Twannberg', 'Veliky Ustyug', 'Vermillion','Weston', 'Willamette', 'Winona', 'Wold Cottage', 'Yamato 000593','Yamato 691','Yamato 791197', 'Yardymly', 'Zagami', 'Zaisho', 'Zaklodzie'] - + yoda: quotes: ["Use your feelings, Obi-Wan, and find him you will.", "Already know you that which you need.", "Adventure. Excitement. A Jedi craves not these things.", "At an end your rule is, and not short enough it was!", "Around the survivors a perimeter create.", "Soon will I rest, yes, forever sleep. Earned it I have. Twilight is upon me, soon night must fall.", "Not if anything to say about it I have", "Through the Force, things you will see. Other places. The future - the past. Old friends long gone.", "Ow, ow, OW! On my ear you are!", "The dark side clouds everything. Impossible to see the future is.", "Size matters not. Look at me. Judge me by my size, do you? Hmm? Hmm. And well you should not. For my ally is the Force, and a powerful ally it is. Life creates it, makes it grow. Its energy surrounds us and binds us. Luminous beings are we, not this crude matter. You must feel the Force around you; here, between you, me, the tree, the rock, everywhere, yes. Even between the land and the ship.", "Younglings, younglings gather ’round.", "Luminous beings are we - not this crude matter.", "Clear your mind must be, if you are to find the villains behind this plot.", "Always two there are, no more, no less. A master and an apprentice.", "Do. Or do not. There is no try.", "Much to learn you still have my old padawan. ... This is just the beginning!", "Good relations with the Wookiees, I have.", "Ready are you? What know you of ready? For eight hundred years have I trained Jedi. My own counsel will I keep on who is to be trained. A Jedi must have the deepest commitment, the most serious mind. This one a long time have I watched. All his life has he looked away - to the future, to the horizon. Never his mind on where he was. Hmm? What he was doing. Hmph. Adventure. Heh. Excitement. Heh. A Jedi craves not these things. You are reckless.", "Truly wonderful, the mind of a child is.", "Always pass on what you have learned.", "Once you start down the dark path, forever will it dominate your destiny, consume you it will.", "Mudhole? Slimy? My home this is!", "Yes, a Jedi’s strength flows from the Force. But beware of the dark side. Anger, fear, aggression; the dark side of the Force are they. Easily they flow, quick to join you in a fight. If once you start down the dark path, forever will it dominate your destiny, consume you it will, as it did Obi-Wan’s apprentice.", "Do not assume anything Obi-Wan. Clear your mind must be if you are to discover the real villains behind this plot.", "Death is a natural part of life. Rejoice for those around you who transform into the Force. Mourn them do not. Miss them do not. Attachment leads to jealously. The shadow of greed, that is.", "Like fire across the galaxy the Clone Wars spread. In league with the wicked Count Dooku, more and more planets slip. Against this threat, upon the Jedi Knights falls the duty to lead the newly formed army of the Republic. And as the heat of war grows, so, to, grows the prowess of one most gifted student of the Force.", "Hmm. In the end, cowards are those who follow the dark side.", "Strong is Vader. Mind what you have learned. Save you it can.", "Pain, suffering, death I feel. Something terrible has happened. Young Skywalker is in pain. Terrible pain", "Difficult to see. Always in motion is the future...", "You will find only what you bring in.", "Feel the force!", "Reckless he is. Matters are worse.", "That is why you fail.", "Your weapons, you will not need them.", "To answer power with power, the Jedi way this is not. In this war, a danger there is, of losing who we are."] @@ -467,3 +467,10 @@ en: - "#{field} #{position}" - "#{field} #{position}" - "#{seniority} #{position}" + + demographic: + race: ["American Indian or Alaska Native", "Asian", "Black or African American", "Native Hawaiian or Other Pacific Islander", "While"] + sex: ["Male", "Female"] + demonym: ["Afghan","Albanian","Algerian","American","Andorran","Angolan","Argentine","Armenian","Aromanian","Aruban","Australian","Austrian","Azerbaijani","Bahamian","Bahraini","Bangladeshi","Barbadian","Basotho","Basque","Belarusian","Belgian","Belizean","Bermudian","Bissau-Guinean","Boer","Bosniak","Brazilian","Breton","Briton","British Virgin Islander","Bruneian","Bulgarian","Burkinabè","Burundian","Cambodian","Cameroonian","Canadian","Catalan","Cape Verdean","Chadian","Chilean","Chinese","Colombian","Comorian","Congolese","Croatian","Cuban","Cypriot","Czech","Dane","Dominican","Dutch","East Timorese","Ecuadorian","Egyptian","Emirati","English","Eritrean","Estonian","Ethiopian","Falkland Islander","Faroese","Finn",Fijian","Filipino","French","Georgian","German","Ghanaian","Gibraltar","Greek","Grenadian","Guatemalan","French Guianan","Guinean","Guyanese","Haitian","Honduran","Hong Konger","Hungarian","Icelander","I-Kiribati","Indian","Indonesian","Iranian","Iraqi","Irish","Israeli","Italian","Ivoirian","Jamaican","Japanese","Jordanian","Kazakh","Kenyan","Korean","Kosovar","Kurd","Kuwaiti","Kyrgyz","Lao","Latvian","Lebanese","Liberian","Libyan","Liechtensteiner","Lithuanian","Luxembourger","Macanese","Macedonian","Malagasy","Malaysian","Malawian","Maldivian","Malian","Maltese","Manx","Mauritian","Mexican","Moldovan","Moroccan","Mongolian","Montenegrin","Namibian","Nepalese","New Zealander","Nicaraguan","Nigerien","Nigerian","Norwegian","Pakistani","Palauan","Palestinian","Panamanian","Papua New Guinean","Paraguayan","Peruvian","Pole","Portuguese","Puerto Rican","Quebecer","Romanian","Russian","Rwandan","Salvadoran","São Toméan","Saudi","Scottish","Senegalese","Serb","Sierra Leonean","Singaporean","Sindhian","Slovak","Slovene","Somali","Somalilander","South African","Spaniard","Sri Lankan","St Lucian","Sudanese","Surinamese","Swede","Swiss","Syriac","Syrian","Tajik","Taiwanese","Tanzanian","Thai","Tibetan","Tobagonian","Trinidadian","Tunisian","Turk","Tuvaluan","Ugandan","Ukrainian","Uruguayan","Uzbek","Vanuatuan","Venezuelan","Vietnamese","Welsh","Yemeni","Zambian","Zimbabwean"] + educational_attainment: ["No schooling completed", "Nursery school", "Kindergarten", "Grade 1 though 11", "12th grade - No Diploma", "Regular high school diploma", "GED or alternative credential", "Some college", "Associate's degree", "Bachelor's degree", "Master's degree", "Professional degree", "Doctorate degree"] + marital_status: ["Married", "Widowed", "Divorced", "Separated", "Never married"] diff --git a/test/test_faker_demographic.rb b/test/test_faker_demographic.rb new file mode 100644 index 0000000000..db2a6d4d06 --- /dev/null +++ b/test/test_faker_demographic.rb @@ -0,0 +1,31 @@ +require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') + +class TestFakerDemographic < Test::Unit::TestCase + def setup + @tester = Faker::Demographic + end + + def test_race + assert @tester.race.match(/\w+/) + end + + def test_educational_attainment + assert @tester.educational_attainment.match(/\w+/) + end + + def test_marital_status + assert @tester.marital_status.match(/\w+/) + end + + def test_demonym + assert @tester.demonym.match(/\w+/) + end + + def test_sex + assert ["Male", "Female"].include?(@tester.sex) + end + + def test_height + assert @tester.height.match(/\w+/) + end +end