Created
July 24, 2014 02:29
-
-
Save shushugah/100fd0a1989a42155bc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Alert < ActiveRecord::Base | |
belongs_to :recipient | |
has_many :services | |
#make variable/method Service.find_by(name: self.service_name).traffic | |
def bad_service? | |
Service.find_by(name: self.service_name).traffic =! "GOOD SERVICE" | |
end | |
def self.current_train_status | |
Service.find_by(name: self.service_name).traffic | |
end | |
#checks if alert object is selected within critical timeframe of recipient | |
def relevant_time? | |
self.start < Time.now && self.end >Time.now | |
end | |
def assign_value_of_changed_status | |
update_attribute(last_alert_status: Service.find_by(name: self.service_name).traffic) | |
end | |
def reset_last_sent | |
if Time.now -alert.last > 0 | |
alert.update_attributes(sent_at: nil, last_alert_status: nil) | |
end | |
def transmogrify | |
assign_value_of_changed_status | |
update_attributes(last_sent: Time.now) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment