-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
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,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" | ||
``` |
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,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 |
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,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 |