class Due::DueSummary

The due class takes a given date and provides several period measures until or since that date.

Attributes

date_time[RW]

Date time field set via the constructor, and the date-time value the due summary stats are based around.

difference[RW]

The numeric field used to store the time difference between the provided date and the current date and time.

now_date_time[RW]

Date time field used to store the current date-time used as part of the due summary calculations.

Public Class Methods

new(the_date_time) click to toggle source

Class constructor that takes in a DateTime argument to base the due-summary stats on.

# File lib/due_summary.rb, line 18
def initialize(the_date_time)
  @date_time = Time.parse(the_date_time)
  @difference = 0.0
end

Public Instance Methods

calc_days_till() click to toggle source

This method calculates the due-summary time difference in days.

# File lib/due_summary.rb, line 91
def calc_days_till
  (calc_hours_till / 24.00).round(2)
end
calc_difference() click to toggle source

This method calculates the due summary time difference between the provided date and the now date.

# File lib/due_summary.rb, line 67
def calc_difference
  @difference = @date_time.to_f - @now_date_time.to_f
end
calc_hours_till() click to toggle source

This method calculates the due-summary time difference in hours.

# File lib/due_summary.rb, line 86
def calc_hours_till
  (calc_mins_till / 60.00).round(2)
end
calc_mins_till() click to toggle source

This method calculates the due-summary time difference in minutes.

# File lib/due_summary.rb, line 81
def calc_mins_till
  (@difference.round(2) / 60.00).round(2)
end
calc_months_till() click to toggle source

This method calculates the due-summary time difference in months.

# File lib/due_summary.rb, line 96
def calc_months_till
  (calc_days_till / 31.0).round(2)
end
calc_weeks_till() click to toggle source

This method calculates the due-summary time difference in weeks.

# File lib/due_summary.rb, line 106
def calc_weeks_till
  (calc_days_till / 7.0).round(2)
end
calc_years_till() click to toggle source

This method calculates the due-summary time difference in years.

# File lib/due_summary.rb, line 101
def calc_years_till
  (calc_months_till / 12.00).round(2)
end
print_summary() click to toggle source

Uses the puts command to output all the due-summary stats as a line separated text.

summary_array() click to toggle source

This method returns an array containing the due-summary stats.

# File lib/due_summary.rb, line 36
def summary_array
  row = []
  column = [DueText.minutes, till_or_since, calc_mins_till.round(2), DueText.minutes_suffix]
  row << column
  column = [DueText.hours, till_or_since, calc_hours_till.round(2), DueText.hours_suffix]
  row << column
  column = [DueText.days, till_or_since, calc_days_till.round(2), DueText.days_suffix]
  row << column
  column = [DueText.weeks, till_or_since, calc_weeks_till.round(2), DueText.weeks_suffix]
  row << column
  column = [DueText.months, till_or_since, calc_months_till.round(2), DueText.months_suffix]
  row << column
  column = [DueText.years, till_or_since, calc_years_till.round(2), DueText.years_suffix]
  row << column
end
summary_table() click to toggle source

This method uses the puts command to output all the due-summary stats as a formatted table.

# File lib/due_summary.rb, line 53
def summary_table
  update_now_date_time
  calc_difference
  labels = [DueText.period, ' ', DueText.duration, DueText.measure]
  rows = summary_array
  puts tabulate(labels, rows, { 'indent' => 4, 'style' => 'fancy' })
end
till_or_since() click to toggle source

This method returns 'since' or 'till' as a description to describe the time difference.

# File lib/due_summary.rb, line 72
def till_or_since
  if @difference.negative?
    DueText.since
  else
    DueText.till
  end
end
update_now_date_time() click to toggle source

This method updates the current date and time regarded as the now current date and time for the due-summary stats.

# File lib/due_summary.rb, line 62
def update_now_date_time
  @now_date_time = Time.new
end