File: extractors.rb

package info (click to toggle)
ruby-email-spec 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 892 kB
  • sloc: javascript: 6,743; ruby: 2,550; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module EmailSpec
  module Extractors
    class Base
      attr_accessor :mail

      def initialize(mail)
        @mail = mail
      end

      def call
        part_body ? HTMLEntities.new.decode(part_body) : ''
      end

      private

      def part_body
        raise NotImplementedError
      end
    end

    class DefaultPartBody < Base
      private

      def part_body
        (mail.html_part || mail.text_part || mail).body
      end
    end

    class HtmlPartBody < Base
      private

      def part_body
        mail.html_part ? mail.html_part.body : nil
      end
    end

    class TextPartBody < Base
      private

      def part_body
        mail.text_part ? mail.text_part.body : nil
      end
    end
  end
end