Class: FlirtChecker::Blood

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Blood.



23
24
25
26
27
# File 'lib/flirt_checker/blood.rb', line 23

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

Instance Attribute Details

#femaleObject

Returns the value of attribute female.



21
22
23
# File 'lib/flirt_checker/blood.rb', line 21

def female
  @female
end

#genotypeObject

Returns the value of attribute genotype.



21
22
23
# File 'lib/flirt_checker/blood.rb', line 21

def genotype
  @genotype
end

#maleObject

Returns the value of attribute male.



21
22
23
# File 'lib/flirt_checker/blood.rb', line 21

def male
  @male
end

Instance Method Details

#comboObject



37
38
39
# File 'lib/flirt_checker/blood.rb', line 37

def combo
  combo_with_rate.keys
end

#combo_with_rateObject



41
42
43
44
45
# File 'lib/flirt_checker/blood.rb', line 41

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