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
린터는 어떻게 수정 될 수 있습니까?Ruby에서 리팩터링하는 법
- 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
이 코드는 작동 코드이므로이 질문을 닫으려고합니다. [Code Review] (http://codereview.stackexchange.com) –
에 게시해야합니다. rubocop rules b/c 나는 매우 간결한 구현이라는 것에 동의한다. – Joe