Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Faker::Blood #1960

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def parse(key)
# In either case the information will be retained for reconstruction of the string.
text = prefix

# If the class has the method, call it, otherwise fetch the transation
# If the class has the method, call it, otherwise fetch the translation
# (e.g., faker.phone_number.area_code)
text += if cls.respond_to?(meth)
cls.send(meth)
Expand Down
48 changes: 48 additions & 0 deletions lib/faker/default/blood.rb
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
13 changes: 13 additions & 0 deletions lib/locales/en/blood.yml
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}"
21 changes: 21 additions & 0 deletions test/faker/default/test_faker_blood.rb
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