Class: MailHogwarts::Message::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/mailhogwarts/message/body.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/mailhogwarts/message/body.rb', line 4

def body
  @body
end

Instance Method Details



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_htmlObject



10
11
12
# File 'lib/mailhogwarts/message/body.rb', line 10

def to_html
  Nokogiri::HTML(@body)
end