Class: Rivendell::Import::Notifier::Mail::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rivendell/import/notifier/mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks) ⇒ Message

Returns a new instance of Message.



42
43
44
# File 'lib/rivendell/import/notifier/mail.rb', line 42

def initialize(tasks)
  @tasks = tasks
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



40
41
42
# File 'lib/rivendell/import/notifier/mail.rb', line 40

def body
  @body
end

#fromObject

Returns the value of attribute from.



40
41
42
# File 'lib/rivendell/import/notifier/mail.rb', line 40

def from
  @from
end

#subjectObject

Returns the value of attribute subject.



40
41
42
# File 'lib/rivendell/import/notifier/mail.rb', line 40

def subject
  @subject
end

#tasksObject (readonly)

Returns the value of attribute tasks.



39
40
41
# File 'lib/rivendell/import/notifier/mail.rb', line 39

def tasks
  @tasks
end

#toObject

Returns the value of attribute to.



40
41
42
# File 'lib/rivendell/import/notifier/mail.rb', line 40

def to
  @to
end

Instance Method Details

#completedObject



46
47
48
# File 'lib/rivendell/import/notifier/mail.rb', line 46

def completed
  tasks.select { |task| task.status.completed? }
end

#deliver!Object



69
70
71
# File 'lib/rivendell/import/notifier/mail.rb', line 69

def deliver!
  mail.deliver!
end

#failedObject



50
51
52
# File 'lib/rivendell/import/notifier/mail.rb', line 50

def failed
  tasks.select { |task| task.status.failed? }
end

#failed?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rivendell/import/notifier/mail.rb', line 54

def failed?
  failed.present?
end

#mailObject



60
61
62
63
64
65
66
67
# File 'lib/rivendell/import/notifier/mail.rb', line 60

def mail
  ::Mail.new.tap do |mail|
    mail.from = from
    mail.to = to
    mail.subject = strip(render(subject))
    mail.body = render(body)
  end
end

#render(template) ⇒ Object



73
74
75
# File 'lib/rivendell/import/notifier/mail.rb', line 73

def render(template)
  ERB.new(template, nil, '%<>-').result(binding)
end

#strip(text) ⇒ Object



77
78
79
# File 'lib/rivendell/import/notifier/mail.rb', line 77

def strip(text)
  text.strip.gsub(/\n[ ]*/m,"")
end