Class: MailHogwarts::Message::Body
- Inherits:
-
Object
- Object
- MailHogwarts::Message::Body
- Defined in:
- lib/mailhogwarts/message/body.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(string) ⇒ Body
constructor
A new instance of Body.
- #links(expression = '') ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(string) ⇒ Body
Returns a new instance of Body.
6 7 8 |
# File 'lib/mailhogwarts/message/body.rb', line 6 def initialize(string) @body = String.new(string) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/mailhogwarts/message/body.rb', line 4 def body @body end |
Instance Method Details
#links(expression = '') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mailhogwarts/message/body.rb', line 14 def links(expression = '') urls = to_html.css('a').map do |link| { href: link['href'], text: link.text, html: link.to_html } end if expression.is_a? Regexp urls.reject do |link| string = link[:href][expression] string.nil? || string.empty? end elsif expression.is_a? String urls.select { |link| link[:href].include? expression } end end |
#to_html ⇒ Object
10 11 12 |
# File 'lib/mailhogwarts/message/body.rb', line 10 def to_html Nokogiri::HTML(@body) end |