From 8dc550d9fdeae059ab2952114b6ec0541bbf8c5c Mon Sep 17 00:00:00 2001 From: Suraj Rajput Date: Sun, 5 Apr 2020 23:34:53 +0530 Subject: [PATCH 1/3] Added Faker::Blood.group --- lib/faker.rb | 2 +- lib/faker/default/blood.rb | 22 ++++++++++++++++++++++ lib/locales/en/blood.yml | 12 ++++++++++++ test/faker/default/test_faker_blood.rb | 13 +++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/faker/default/blood.rb create mode 100644 lib/locales/en/blood.yml create mode 100644 test/faker/default/test_faker_blood.rb diff --git a/lib/faker.rb b/lib/faker.rb index 84a8596e4a..cc3d8a35b8 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -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) diff --git a/lib/faker/default/blood.rb b/lib/faker/default/blood.rb new file mode 100644 index 0000000000..b553c3a1db --- /dev/null +++ b/lib/faker/default/blood.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Faker + class Blood < Base + flexible :blood + + class << self + ## + # Produces a random blood group name. + # + # @return [String] + # + # @example + # Faker::Blood.group #=> "AB-" + # + # @faker.version next + def group + fetch('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..57e64f6168 --- /dev/null +++ b/lib/locales/en/blood.yml @@ -0,0 +1,12 @@ +en: + faker: + blood: + group: + - O+ + - O- + - A+ + - A- + - B+ + - B- + - AB+ + - AB- diff --git a/test/faker/default/test_faker_blood.rb b/test/faker/default/test_faker_blood.rb new file mode 100644 index 0000000000..70014fa336 --- /dev/null +++ b/test/faker/default/test_faker_blood.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerBlood < Test::Unit::TestCase + def setup + @tester = Faker::Blood + end + + def test_group + assert @tester.group.match(/[ABO]{1,2}[+-]/i) + end +end From 96f512e84edf499d1f21420328853a0be2afc9ca Mon Sep 17 00:00:00 2001 From: Suraj Rajput Date: Mon, 4 May 2020 12:05:02 +0530 Subject: [PATCH 2/3] Added type and rh_factor methods for blood --- lib/faker/default/blood.rb | 28 +++++++++++++++++++++++++- lib/locales/en/blood.yml | 17 ++++++++-------- test/faker/default/test_faker_blood.rb | 8 ++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/faker/default/blood.rb b/lib/faker/default/blood.rb index b553c3a1db..13b9a638a1 100644 --- a/lib/faker/default/blood.rb +++ b/lib/faker/default/blood.rb @@ -5,6 +5,32 @@ 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. # @@ -15,7 +41,7 @@ class << self # # @faker.version next def group - fetch('blood.group') + parse('blood.group') end end end diff --git a/lib/locales/en/blood.yml b/lib/locales/en/blood.yml index 57e64f6168..d22bee78f6 100644 --- a/lib/locales/en/blood.yml +++ b/lib/locales/en/blood.yml @@ -1,12 +1,13 @@ en: faker: blood: + type: + - O + - A + - B + - AB + rh_factor: + - + + - '-' group: - - O+ - - O- - - A+ - - A- - - B+ - - B- - - AB+ - - AB- + - "#{type}#{rh_factor}" diff --git a/test/faker/default/test_faker_blood.rb b/test/faker/default/test_faker_blood.rb index 70014fa336..a34f25a80e 100644 --- a/test/faker/default/test_faker_blood.rb +++ b/test/faker/default/test_faker_blood.rb @@ -7,6 +7,14 @@ def setup @tester = Faker::Blood end + def test_type + assert @tester.group.match(/[ABO]{1,2}/i) + end + + def test_rh_factor + assert @tester.group.match(/[+-]/i) + end + def test_group assert @tester.group.match(/[ABO]{1,2}[+-]/i) end From 7943853afd2438734176fa9ccedae4ecdf8dcd76 Mon Sep 17 00:00:00 2001 From: Suraj Rajput Date: Tue, 5 May 2020 16:03:40 +0530 Subject: [PATCH 3/3] Updated test cases --- test/faker/default/test_faker_blood.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/faker/default/test_faker_blood.rb b/test/faker/default/test_faker_blood.rb index a34f25a80e..ca0f919622 100644 --- a/test/faker/default/test_faker_blood.rb +++ b/test/faker/default/test_faker_blood.rb @@ -8,14 +8,14 @@ def setup end def test_type - assert @tester.group.match(/[ABO]{1,2}/i) + assert @tester.type.match(/^(AB|A|B|O)$/) end def test_rh_factor - assert @tester.group.match(/[+-]/i) + assert @tester.rh_factor.match(/[+-]/) end def test_group - assert @tester.group.match(/[ABO]{1,2}[+-]/i) + assert @tester.group.match(/^(AB|A|B|O)[+-]$/) end end