puzzle-scoreboard/app/controllers/concerns/completions_concern.rb
sto 7ce684ced9
Some checks failed
CI / scan_ruby (push) Successful in 15s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Has been cancelled
Move completions methods to a concern
2025-03-23 09:25:32 +01:00

31 lines
792 B
Ruby

module CompletionsConcern
extend ActiveSupport::Concern
def pad(n)
if n > 9
return n.to_s
end
"0" + n.to_s
end
def display_time(seconds)
if seconds > 3600
hours = seconds / 3600
return hours.to_s + ":" + display_time(seconds % 3600)
elsif seconds > 60
minutes = seconds / 60
return pad(minutes) + ":" + display_time(seconds % 60)
end
pad(seconds)
end
def extend_completions!(completions)
current_time_from_start = 0
@completions.each do |completion|
completion.display_time_from_start = display_time(completion.time_seconds)
completion.display_relative_time = display_time(completion.time_seconds - current_time_from_start)
current_time_from_start += completion.time_seconds
end
end
end