Refactor Timeframer#datetime (#3117) [ci skip]
This commit is contained in:
parent
b34387f384
commit
c15a2379e7
1 changed files with 10 additions and 11 deletions
|
|
@ -1,20 +1,19 @@
|
|||
class Timeframer
|
||||
attr_accessor :timeframe
|
||||
|
||||
DATETIMES = {
|
||||
"infinity" => 5.years.ago,
|
||||
"year" => 1.year.ago,
|
||||
"month" => 1.month.ago,
|
||||
"week" => 1.week.ago,
|
||||
"latest" => "latest"
|
||||
}.freeze
|
||||
|
||||
def initialize(timeframe)
|
||||
@timeframe = timeframe
|
||||
end
|
||||
|
||||
def datetime
|
||||
if timeframe == "infinity"
|
||||
5.years.ago
|
||||
elsif timeframe == "week"
|
||||
1.week.ago
|
||||
elsif timeframe == "month"
|
||||
1.month.ago
|
||||
elsif timeframe == "year"
|
||||
1.year.ago
|
||||
elsif timeframe == "latest"
|
||||
"latest"
|
||||
end
|
||||
DATETIMES[timeframe]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue