Class: Mailbot::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/mailbot/entry.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

SYNC_MARK =
""
HEADER_LINE_PATTERN =
/^#\s+(#{SYNC_MARK}\s*)?(.+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Entry

Returns a new instance of Entry.

Parameters:

  • text (String)

    The raw text of this entry



11
12
13
# File 'lib/mailbot/entry.rb', line 11

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/mailbot/entry.rb', line 8

def text
  @text
end

Instance Method Details

#render_bodyString

Returns An HTML representation of this entry.

Returns:

  • (String)

    An HTML representation of this entry



21
22
23
# File 'lib/mailbot/entry.rb', line 21

def render_body
  Mailbot::Renderer.render @text.sub(HEADER_LINE_PATTERN, "")
end

#subjectString

Returns A subject of this entry.

Returns:

  • (String)

    A subject of this entry



16
17
18
# File 'lib/mailbot/entry.rb', line 16

def subject
  headers.reject { |header| header =~ /#{SYNC_MARK}/ }.first
end

#syncMailbot::Entry

Returns A synced entry.

Returns:



31
32
33
# File 'lib/mailbot/entry.rb', line 31

def sync
  Entry.new(@text.sub HEADER_LINE_PATTERN, "# #{SYNC_MARK} \\2")
end

#synced?Boolean

Returns True if this entry is already synced to Mailbox.

Returns:

  • (Boolean)

    True if this entry is already synced to Mailbox



26
27
28
# File 'lib/mailbot/entry.rb', line 26

def synced?
  headers.include? SYNC_MARK
end

#to_sString

Note:

Overridden

Returns A String representation of this entry.

Returns:

  • (String)

    A String representation of this entry



37
38
39
# File 'lib/mailbot/entry.rb', line 37

def to_s
  @text
end