I have three types of variable assign expression with multiple expressions.
It looks ugly, but I'm not sure how to make it more readable.
Type 1
following_triggers = alarm_test_group.map{ |alarm_test|
self.class.where{ sony_alarm_test_id.eq(alarm_test.id) }
.where{ utc_time.gt(my{utc_time}+TIME_CORRECTION) }
.where{ name =~ my{self.name} }
.first
}.select!{|t| t != nil}
Type 1-1
following_triggers = alarm_test_group.map do |alarm_test|
self.class.where{ sony_alarm_test_id.eq(alarm_test.id) }
.where{ utc_time.gt(my{utc_time}+TIME_CORRECTION) }
.where{ name =~ my{self.name} }
.first
end.select!{|t| t != nil}
Type 2
q = self.class
.where{ (utc_time.gt(my{utc_time}+time_correction)) & utc_time.lt(closest_trigger_utc_time) }
.where{ name =~ event_name }
.where{ sony_alarm_test_id.eq(my{sony_alarm_test.id})}
Type 3
previous_alarms = \
get_alarm_tests_in_the_same_group.map do |alarm_test|
self.class
.where{sony_alarm_test_id.eq(alarm_test.id)}
.where{ name =~ "AlarmLogger" }
.where{utc_time.lt(my{self.utc_time})}
.last
end
@@following[event_type.to_sym] = \
followed.following(event_type)
.where{ sony_alarm_test_id == followed.sony_alarm_test_id }
.limit(CACHE_UPPER_BOUND).to_a.dup
where
orlimit
. If those are fromActiveRecord
, you should add that as a tag. Can the threewhere
statements be combined into one, using&&
? Yes, you needself
withself.class
, but do you need the other.self
's? – Cary Swoveland Jun 29 at 18:48