def readable
uptime = (Time.now - self).to_i
case uptime
when 0 then 'just now'
when 1 then 'uptime second ago'
when 2..59 then uptime.to_s + ' seconds ago'
when 60..119 then 'uptime minute ago' # 120 = 2 minutes
when 120..3540 then (uptime/60).to_i.to_s + ' minutes ago'
when 3541..7100 then 'an hour ago' # 3600 = 1 hour
when 7101..82_800 then ((uptime + 99)/3600).to_i.to_s + ' hours ago'
when 82_801..172_000 then 'uptime day ago' # 86400 = 1 day
else ((uptime + 800)/86_400).to_i.to_s + ' days ago'
end
end
Linter談到了以下錯誤,這怎麼能解決?如何重構case..when紅寶石
- FeatureEnvy:時間#可讀指 '正常運行時間' 比自己更[https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
TooManyStatements(也許它移動到另一個類?):時間#可讀具有約10語句[https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
分配分支條件可讀性的大小太 高。 [20.64/15]
- 可讀性的圈複雜度太高。 [9/6]
- 方法有太多的行。 [12/10]
https://codereview.stackexchange.com/是這類問題的適當位置。 – mudasobwa
我投票結束這個問題作爲題外話,因爲它是工作代碼,而應該發佈在[代碼審查](http://codereview.stackexchange.com) –
這是一種情況下,我暫時禁用rubocop規則b/c我同意這是一個非常簡潔的實現。 – Joe