framingham/heartdisease.rb in framingham-0.1.20130712221655 vs framingham/heartdisease.rb in framingham-0.1.20130719170918

- old
+ new

@@ -7,13 +7,15 @@ options = NORMAL.merge options @age = options[:age].to_f @blood_pressure = options[:blood_pressure].to_f @blood_pressure_treatment = options[:blood_pressure_treatment] ? :treated : :untreated @body_mass_index = options[:body_mass_index].to_f - @gender = options[:gender] + @gender = options[:gender].to_sym @diabetes = to_i options[:diabetes] @smoker = to_i options[:smoker] + #validate + raise ERRORS[:gender] unless GENDERS.include? @gender rescue => exception abort "\033[31merror: " + exception.message + "\033[0m" else #calculate start_beta = BETA_ZERO[@gender] + Math.log(@age) * AGE[@gender] @@ -77,12 +79,10 @@ '%5.1f' % ((1000 * _[:risk]).round / 10.0) + '%5.1f' % ((1000 * _[:normal]).round / 10.0) + '%5.1f' % ((1000 * _[:optimal]).round / 10.0) end -$, = ", " #default join - NORMAL = { #default options age: 30, blood_pressure: 125, blood_pressure_treatment: false, body_mass_index: 22.5, @@ -100,19 +100,14 @@ BLOOD_PRESSURE_RANGE = (90..200) unless defined? BLOOD_PRESSURE_RANGE BMI_RANGE = (15..50) unless defined? BMI_RANGE -GENDERS = [ - :male, - :female -] unless defined? GENDERS - ERRORS = { age: "age must be in range: " + AGE_RANGE.to_s, blood_pressure: "blood pressure must be in range: " + BLOOD_PRESSURE_RANGE.to_s, bmi: "bmi must be in range: " + BMI_RANGE.to_s, - gender: "invalid gender, options: " + GENDERS.join, + gender: "invalid gender, options: " + GENDERS.join } unless defined? ERRORS BETA_ZERO = { male: -23.9388, female: -26.0145