diff --git a/lib/faker.rb b/lib/faker.rb index 6f78418b30..f34d041f09 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -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) diff --git a/lib/faker/default/blood.rb b/lib/faker/default/blood.rb new file mode 100644 index 0000000000..13b9a638a1 --- /dev/null +++ b/lib/faker/default/blood.rb @@ -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 diff --git a/lib/locales/en/blood.yml b/lib/locales/en/blood.yml new file mode 100644 index 0000000000..d22bee78f6 --- /dev/null +++ b/lib/locales/en/blood.yml @@ -0,0 +1,13 @@ +en: + faker: + blood: + type: + - O + - A + - B + - AB + rh_factor: + - + + - '-' + group: + - "#{type}#{rh_factor}" diff --git a/test/faker/default/test_faker_blood.rb b/test/faker/default/test_faker_blood.rb new file mode 100644 index 0000000000..ca0f919622 --- /dev/null +++ b/test/faker/default/test_faker_blood.rb @@ -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