Skip to content

Instantly share code, notes, and snippets.

@CodisRedding
Created July 22, 2013 16:52
Show Gist options
  • Save CodisRedding/6055505 to your computer and use it in GitHub Desktop.
Save CodisRedding/6055505 to your computer and use it in GitHub Desktop.
require 'yaml'
class Watt
attr_reader :range
attr_reader :watts
def initialize(range, watts, seconds)
@range = range
@watts = watts
@seconds = seconds
end
def total_minutes
if @seconds > 0
(@seconds / 60).round(2)
else
0
end
end
def total_time
if @seconds < 60
"#{Time.at(@seconds).gmtime.strftime('%_s')}s"
elsif @seconds.between?(60, 3600)
Time.at(@seconds).gmtime.strftime('%_m:%S')
else
Time.at(@seconds).gmtime.strftime('%l:%M:%S')
end
end
def percentage(total_mins)
if self.total_minutes > 0
((self.total_minutes.to_f / total_mins.to_f) * 100).round.to_s + '%'
else
"0%"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment