Skip to content

Commit

Permalink
fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
lctseng committed Aug 4, 2017
1 parent 318100a commit 6f0cee9
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,43 @@ def self.checkin_staff(user)
return false if user.nil?
result = user.checkin
return nil unless result
greeting = genrate_greeting(user)
greeting = generate_greeting(user)
{ auth: true, reason: 'checkin', message: "#{greeting}\n#{user.ascii_only_name}" }
end

def self.genrate_greeting(user)
def self.generate_greeting(user)
if (user.check_records.today.count % 2).zero?
# clock out
'Good Bye!'
clock_out_greeting
else
# clock in
time_limit = Time.parse(Settings.clockin_time_limit)
time_now = Time.zone.now
if time_now > time_limit
# Late
seconds = time_now - time_limit
min = (seconds / 60.0).ceil
hour = min / 60
min %= 60
"Late for #{hour}h#{min}m!"
else
# In time
'Hello'
end
clock_in_greeting
end
end

def self.compute_late_time(time_now, time_limit)
seconds = time_now - time_limit
min = (seconds / 60.0).ceil
hour = min / 60
min %= 60
[hour, min]
end

def self.clock_in_greeting
time_limit = Time.zone.parse(Settings.clockin_time_limit)
time_now = Time.zone.now
if time_now > time_limit # Late
hour, min = compute_late_time(time_now, time_limit)
"Late for #{hour}h#{min}m!"
else # In time
'Hello'
end
end

def self.clock_out_greeting
'Good Bye!'
end

def ascii_only_name
if name.ascii_only?
name
Expand Down

0 comments on commit 6f0cee9

Please sign in to comment.