Skip to content

Commit

Permalink
better readme
Browse files Browse the repository at this point in the history
  • Loading branch information
elorest committed Oct 1, 2012
1 parent 037d461 commit 03d5d7c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/easy_timer.rb
Expand Up @@ -11,13 +11,14 @@ def timer(options = {}, &block)
yield
total_time = Time.at(Time.now - start_time)
if options[:verbose] || options[:v]

end
return total_time
return total_time.verbose
else
return total_time
end
end
end

def to_verbose
def verbose
time_hash = {}
seconds = self.to_i
milliseconds = (self.to_f - seconds)
Expand All @@ -26,10 +27,10 @@ def to_verbose
time_hash[:hours], seconds = seconds.divmod(3600)
time_hash[:minutes], seconds = seconds.divmod(60)
time_hash[:seconds] = seconds + milliseconds
return time_hash.select{|k,v| v > 0}.inject(""){|vs, array|
return time_hash.select{|k,v| v > 0}.inject([]){|verbose, array|
k, v = array
vs << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{k} "
}.strip
verbose << "#{v.is_a?(Float) ? sprintf("%.2f", v) : v} #{k}"
}.join(" ")
end
end

Expand Down

0 comments on commit 03d5d7c

Please sign in to comment.