Skip to content

Instantly share code, notes, and snippets.

@shushugah
Created July 24, 2014 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shushugah/100fd0a1989a42155bc9 to your computer and use it in GitHub Desktop.
Save shushugah/100fd0a1989a42155bc9 to your computer and use it in GitHub Desktop.
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