I wrote a transform to capture one of the following words: “first”, “second”, “third”, or “fourth” representing quarters of a year. Here’s what I wrote, I was hoping there might be a much simpler way of doing this. Any thoughts?
CAPTURE_QUARTER = Transform /^(first|second|third|fourth)$/ do |quarter|
case quarter
when 'first'
1
when 'second'
2
when 'third'
3
when 'fourth'
4
end
end
Thanks in advance!
UPDATE:
Possible solution:
CAPTURE_QUARTER = Transform /^(first|second|third|fourth)$/ do |quarter|
{first: 1, second: 2, third: 3, fourth: 4}[quarter.to_sym]
end
Thoughts on this one?
I can suggest you yet another way of doing that: