class Hometime
Public Class Methods
initialize(duration, start_time)
click to toggle source
# File lib/hometime.rb, line 2 def self.initialize(duration, start_time) @time = start_time @duration = duration { 'leave_time': leave_time.strftime('%H:%M'), 'hours_remaining': unit_formatted('hour', hours), 'minutes_remaining': unit_formatted('minute', minutes), 'seconds_remaining': unit_formatted('second', seconds) } end
Private Class Methods
current_time()
click to toggle source
# File lib/hometime.rb, line 26 def self.current_time Time.now end
days_until_important_date_date()
click to toggle source
# File lib/hometime.rb, line 76 def self.days_until_important_date_date ((((important_date_date - current_time) / 60) / 60) / 24).ceil end
hour()
click to toggle source
# File lib/hometime.rb, line 30 def self.hour @time.partition(':').first end
hours()
click to toggle source
# File lib/hometime.rb, line 56 def self.hours (seconds_remaining / (60 * 60)).floor end
important_date_date()
click to toggle source
# File lib/hometime.rb, line 71 def self.important_date_date this_year = Time.now.strftime('%Y').to_i Time.new(this_year, 12, 25) end
important_dates()
click to toggle source
TODO - Read important date from file
# File lib/hometime.rb, line 65 def self.important_dates file = File.read('../data/dates.json') puts "#{days_until_important_date_date} days until Christmas!" if days_until_important_date_date > 0 end
leave_time()
click to toggle source
Time to leave
# File lib/hometime.rb, line 17 def self.leave_time Time.new( current_time.year, current_time.month, current_time.day, hour, minute, 0 ) + @duration * 60 * 60 end
minute()
click to toggle source
# File lib/hometime.rb, line 34 def self.minute @time.partition(':').last end
minutes()
click to toggle source
# File lib/hometime.rb, line 52 def self.minutes ((seconds_remaining / 60) % 60).floor end
seconds()
click to toggle source
# File lib/hometime.rb, line 48 def self.seconds (seconds_remaining % 60).floor end
seconds_remaining()
click to toggle source
# File lib/hometime.rb, line 60 def self.seconds_remaining leave_time - current_time end
unit_formatted(unit, value)
click to toggle source
Time remaining
# File lib/hometime.rb, line 39 def self.unit_formatted(unit, value) case when value == 1 "#{value} #{unit} " when value > 1 && value < 60 "#{value} #{unit}s " end end