Class: Poodle::Blood

Inherits:
Object
  • Object
show all
Defined in:
lib/poodle/blood.rb

Constant Summary collapse

BLOOD_GROUP =

key: :phenotype value: [genotypes]

{
  a: ["A","A","A","O"],
  b: ["B","B","B","O"],
  o: ["O","O"],
  ab: ["A","B"]
}

Instance Method Summary collapse

Constructor Details

#initialize(male, female, genotype: false) ⇒ Blood

Returns a new instance of Blood.



14
15
16
17
18
19
# File 'lib/poodle/blood.rb', line 14

def initialize(male, female, genotype: false)
  @male = male
  @female = female
  @genotype = genotype 
  @blood_combination = []
end

Instance Method Details

#inheritObject



21
22
23
24
25
26
27
28
# File 'lib/poodle/blood.rb', line 21

def inherit
  valid_blood_type?
  if @genotype
    blood_combination.uniq 
  else
    blood_combination.collect! { |e| to_phenotype(e) }.uniq
  end
end

#inherit_with_rateObject



30
31
32
33
34
# File 'lib/poodle/blood.rb', line 30

def inherit_with_rate
  valid_blood_type?
  hash = blood_combination.reduce(Hash.new(0)) { |h,v| h[@genotype ? v : to_phenotype(v)] += 1 ; h }
  hash.each_with_object({}) { |(k,v), h| h[k] = v.to_f / blood_combination.size.to_f }
end