Class: EmailTracker::Email
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- EmailTracker::Email
- Defined in:
- app/models/email_tracker/email.rb
Class Method Summary collapse
Instance Method Summary collapse
- #num_links_clicked(since = nil) ⇒ Object
- #opened_percentage(since = nil) ⇒ Object
- #sent! ⇒ Object
- #times_opened(since = nil) ⇒ Object
Class Method Details
.for_email(data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/email_tracker/email.rb', line 31 def self.for_email(data) if data[:owner] data[:owner_type] = data[:owner].class.name data[:owner_id] = data[:owner].id end hash = { mailer: data[:mailer], action: data[:action], subject: data[:subject], owner_type: data[:owner_type], owner_id: data[:owner_id] } unless email = self.where(hash).first email = self.new(hash, as: :email_tracker_internals) email.save! end email end |
Instance Method Details
#num_links_clicked(since = nil) ⇒ Object
25 26 27 28 29 |
# File 'app/models/email_tracker/email.rb', line 25 def num_links_clicked(since = nil) c = clicks.scoped c = c.where("created_at > ?", since) if since c.count end |
#opened_percentage(since = nil) ⇒ Object
21 22 23 |
# File 'app/models/email_tracker/email.rb', line 21 def opened_percentage(since = nil) ((times_opened(since).to_f / times_sent) * 100).to_i end |
#sent! ⇒ Object
11 12 13 |
# File 'app/models/email_tracker/email.rb', line 11 def sent! increment!(:times_sent) end |
#times_opened(since = nil) ⇒ Object
15 16 17 18 19 |
# File 'app/models/email_tracker/email.rb', line 15 def times_opened(since = nil) o = opens.scoped o = o.where("created_at > ?", since) if since o.count end |