Refactor Timeframer#datetime (#3117) [ci skip]

This commit is contained in:
Arun Kumar 2019-06-11 09:29:10 -05:00 committed by Mac Siri
parent b34387f384
commit c15a2379e7

View file

@ -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