Created
July 22, 2013 16:52
-
-
Save CodisRedding/6055505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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