Permalink
Browse files

Extract FakeBirthdate class for generating a consistent fake brithdat…

…e for a Patient
  • Loading branch information...
1 parent 67b31e9 commit b29249c3a19e223f5e2a9aa42b92e5dc8e12c3ae @nilbus committed Jul 10, 2015
Showing with 23 additions and 4 deletions.
  1. +22 −0 app/models/fake_birthdate.rb
  2. +1 −4 app/models/patient.rb
@@ -0,0 +1,22 @@
+class FakeBirthdate
+ def initialize(patient)
+ @random_seed = patient.pid.gsub('.', '').gsub('-', '').to_i
+ end
+
+ def random_reasonable_birthdate
+ from = 0.0
+ to = Time.now
+ random_number = Random.new(@random_seed).rand
+ Time.at(from + random_number * (to.to_f - from.to_f)) - 25.years
+ end
+
+ def to_s
+ formatted random_reasonable_birthdate
+ end
+
+ private
+
+ def formatted(date)
+ date.to_s.gsub(/\d{2}:\d{2}:\d{2} -\d{4}/, '').strip
+ end
+end
@@ -29,10 +29,7 @@ def weight
end
def birthday
- from = 0.0
- to = Time.now
- random_number = Random.new(@pid.gsub('.', '').gsub('-', '').to_i).rand
- (Time.at(from + random_number * (to.to_f - from.to_f))-25.years).to_s.gsub(/\d{2}:\d{2}:\d{2} -\d{4}/, '').strip
+ FakeBirthdate.new(patient).to_s
end
def age

0 comments on commit b29249c

Please sign in to comment.