Skip to content

Commit

Permalink
Added Faker::Blood (#1960)
Browse files Browse the repository at this point in the history
* Added Faker::Blood.group

* Added type and rh_factor methods for blood

* Updated test cases
  • Loading branch information
surajput32 committed May 19, 2020
1 parent a880969 commit ea5a9f1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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

0 comments on commit ea5a9f1

Please sign in to comment.