Refactor: Simplify TimeWindowParser using Rails convenience methods
- Replace `beginning_of_day..end_of_day` with `all_day` - Replace `beginning_of_week..end_of_week` with `all_week` - Replace `beginning_of_month..end_of_month` with `all_month` - Replace `beginning_of_year..end_of_year` with `all_year` These changes improve code readability by using idiomatic Rails methods that accomplish the same thing in a more concise and expressive way.
This commit is contained in:
@@ -31,21 +31,21 @@ class TimeWindowParser
|
|||||||
def parse(string)
|
def parse(string)
|
||||||
case normalize(string)
|
case normalize(string)
|
||||||
when "today"
|
when "today"
|
||||||
now.beginning_of_day..now.end_of_day
|
now.all_day
|
||||||
when "yesterday"
|
when "yesterday"
|
||||||
(now - 1.day).beginning_of_day..(now - 1.day).end_of_day
|
(now - 1.day).all_day
|
||||||
when "thisweek"
|
when "thisweek"
|
||||||
now.beginning_of_week..now.end_of_week
|
now.all_week
|
||||||
when "thismonth"
|
when "thismonth"
|
||||||
now.beginning_of_month..now.end_of_month
|
now.all_month
|
||||||
when "thisyear"
|
when "thisyear"
|
||||||
now.beginning_of_year..now.end_of_year
|
now.all_year
|
||||||
when "lastweek"
|
when "lastweek"
|
||||||
(now - 1.week).beginning_of_week..(now - 1.week).end_of_week
|
(now - 1.week).all_week
|
||||||
when "lastmonth"
|
when "lastmonth"
|
||||||
(now - 1.month).beginning_of_month..(now - 1.month).end_of_month
|
(now - 1.month).all_month
|
||||||
when "lastyear"
|
when "lastyear"
|
||||||
(now - 1.year).beginning_of_year..(now - 1.year).end_of_year
|
(now - 1.year).all_year
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user