Class: DigestEmail::DigestParser

Inherits:
Object
  • Object
show all
Extended by:
DigestParserValidator
Defined in:
lib/digest_email/digest_parser.rb

Class Method Summary collapse

Methods included from DigestParserValidator

valid_index?, validate_index, validate_indices

Class Method Details

.parse(digest) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/digest_email/digest_parser.rb', line 7

def self.parse(digest)
  begin
    validate_indices(digest, ["header", "items", "footer"])

    header = parse_header(digest["header"])
    body   = parse_items(digest["items"])
    footer = parse_footer(digest["footer"])

    DigestEmail::Digest.new(header, body, footer)
  rescue Exception => e
    raise "Failed to parse digest: #{e.message}"
  end
end


36
37
38
39
# File 'lib/digest_email/digest_parser.rb', line 36

def self.parse_footer(footer)
  validate_indices(footer, ["signature", "sponsors_image"])
  DigestEmail::DigestFooter.new footer
end

.parse_header(header) ⇒ Object



21
22
23
24
# File 'lib/digest_email/digest_parser.rb', line 21

def self.parse_header(header)
  validate_index(header, "title")
  DigestEmail::DigestHeader.new header
end

.parse_item(item) ⇒ Object



30
31
32
33
34
# File 'lib/digest_email/digest_parser.rb', line 30

def self.parse_item(item)
  validate_indices(item, ["list_title", "image", "title", "body"])

  DigestEmail::DigestItem.new item
end

.parse_items(items) ⇒ Object



26
27
28
# File 'lib/digest_email/digest_parser.rb', line 26

def self.parse_items(items)
  DigestEmail::DigestItems.new items.map{|item| parse_item(item)}
end