Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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
share|improve this question
1  
have you considered using scopes? –  Sean Jun 27 at 21:03
    
I don't recognize where or limit. If those are from ActiveRecord, you should add that as a tag. Can the three where statements be combined into one, using &&? Yes, you need self with self.class, but do you need the other .self's? –  Cary Swoveland Jun 29 at 18:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.