Class: AgeCalculator

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

Instance Method Summary collapse

Instance Method Details

#compute(birth_date, current_date) ⇒ Hash

Calculates an age based on the given current date.

Parameters:

  • birth_date

    Date

  • current_date

    Date

Returns:

  • (Hash)

    containing the year, month and day



14
15
16
17
18
19
20
21
# File 'lib/age_calculator.rb', line 14

def compute(birth_date, current_date)
  calculation = build_calculation(birth_date, current_date)
  compute_days(calculation, birth_date, current_date)
  compute_months(calculation, birth_date, current_date)
  handle_future_dates(calculation)

  build_hash(calculation)
end