Class: AbAdmin::Mailers::MailAttachHelper::MailAttacher
- Defined in:
- lib/ab_admin/mailers/mail_attach_helper.rb
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ MailAttacher
constructor
A new instance of MailAttacher.
- #parse_images ⇒ Object
- #replace_attaches(attaches) ⇒ Object
Constructor Details
#initialize(text) ⇒ MailAttacher
Returns a new instance of MailAttacher.
15 16 17 18 19 |
# File 'lib/ab_admin/mailers/mail_attach_helper.rb', line 15 def initialize(text) @text = text.gsub(/(\n|\t|\r)/, ' ').gsub(/>\s*</, '><').squeeze(' ') @images = [] parse_images end |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
13 14 15 |
# File 'lib/ab_admin/mailers/mail_attach_helper.rb', line 13 def images @images end |
#text ⇒ Object
Returns the value of attribute text.
13 14 15 |
# File 'lib/ab_admin/mailers/mail_attach_helper.rb', line 13 def text @text end |
Instance Method Details
#parse_images ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ab_admin/mailers/mail_attach_helper.rb', line 21 def parse_images raw_res = @text.scan(/<img[^>]*?src="(\/[^"]*)/).flatten raw_res.map do |r| r_clear = r.gsub(/\?[^?]*$/, '') @images << [r, Rails.root.join('public', r_clear.slice(1..-1)).to_s, File.basename(r_clear)] end @images end |
#replace_attaches(attaches) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/ab_admin/mailers/mail_attach_helper.rb', line 30 def replace_attaches(attaches) @images.each do |image| @text = @text.gsub(image[0], attaches[image[2]].try(:url)) end @text end |