-
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.
* Added Faker::Blood.group * Added type and rh_factor methods for blood * Updated test cases
- Loading branch information
1 parent
a880969
commit ea5a9f1
Showing
4 changed files
with
83 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,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faker | ||
class Blood < Base | ||
flexible :blood | ||
|
||
class << self | ||
## | ||
# Produces a random blood type. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Blood.type #=> "AB" | ||
# | ||
# @faker.version next | ||
def type | ||
fetch('blood.type') | ||
end | ||
|
||
## | ||
# Produces a random blood RH-Factor. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Blood.rh_factor #=> "-" | ||
# | ||
# @faker.version next | ||
def rh_factor | ||
fetch('blood.rh_factor') | ||
end | ||
|
||
## | ||
# Produces a random blood group name. | ||
# | ||
# @return [String] | ||
# | ||
# @example | ||
# Faker::Blood.group #=> "AB-" | ||
# | ||
# @faker.version next | ||
def group | ||
parse('blood.group') | ||
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,13 @@ | ||
en: | ||
faker: | ||
blood: | ||
type: | ||
- O | ||
- A | ||
- B | ||
- AB | ||
rh_factor: | ||
- + | ||
- '-' | ||
group: | ||
- "#{type}#{rh_factor}" |
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
class TestFakerBlood < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Blood | ||
end | ||
|
||
def test_type | ||
assert @tester.type.match(/^(AB|A|B|O)$/) | ||
end | ||
|
||
def test_rh_factor | ||
assert @tester.rh_factor.match(/[+-]/) | ||
end | ||
|
||
def test_group | ||
assert @tester.group.match(/^(AB|A|B|O)[+-]$/) | ||
end | ||
end |