Class: Waw::Tools::MailAgent::Mailbox
- Defined in:
- lib/waw/tools/mail/mailbox.rb
Overview
Helper for testing purposes only.
Instance Method Summary collapse
-
#[](id) ⇒ Object
Returns the id-th mail in the mailbox.
-
#clear ⇒ Object
Removes all mails.
-
#empty? ⇒ Boolean
Checks if the mailbox is empty or not.
-
#initialize(mail_address) ⇒ Mailbox
constructor
Creates an empty mailbox for a given adress.
-
#is_read?(id) ⇒ Boolean
Checks if a mail is marked as read.
-
#push(mail) ⇒ Object
(also: #<<)
Pushes a mail inside the mailbox, returns an id.
-
#read(id) ⇒ Object
Marks a mail as read and returns it.
-
#size ⇒ Object
Returns the number of mails in this mailbox.
Constructor Details
#initialize(mail_address) ⇒ Mailbox
Creates an empty mailbox for a given adress
8 9 10 11 |
# File 'lib/waw/tools/mail/mailbox.rb', line 8 def initialize(mail_address) @mail_address = mail_address @mails = [] end |
Instance Method Details
#[](id) ⇒ Object
Returns the id-th mail in the mailbox. Returns nil if no such mail can be found
32 33 34 35 36 |
# File 'lib/waw/tools/mail/mailbox.rb', line 32 def [](id) mail = @mails[id] return nil unless mail mail[0] end |
#clear ⇒ Object
Removes all mails
55 56 57 |
# File 'lib/waw/tools/mail/mailbox.rb', line 55 def clear @mails.clear end |
#empty? ⇒ Boolean
Checks if the mailbox is empty or not
19 20 21 |
# File 'lib/waw/tools/mail/mailbox.rb', line 19 def empty? @mails.empty? end |
#is_read?(id) ⇒ Boolean
Checks if a mail is marked as read. Returns nil if no such mail can be found
40 41 42 43 44 |
# File 'lib/waw/tools/mail/mailbox.rb', line 40 def is_read?(id) mail = @mails[id] return nil unless mail mail[1] end |
#push(mail) ⇒ Object Also known as: <<
Pushes a mail inside the mailbox, returns an id
24 25 26 27 |
# File 'lib/waw/tools/mail/mailbox.rb', line 24 def push(mail) @mails << [mail, false] @mails.size-1 end |
#read(id) ⇒ Object
Marks a mail as read and returns it
47 48 49 50 51 52 |
# File 'lib/waw/tools/mail/mailbox.rb', line 47 def read(id) mail = @mails[id] return nil unless mail mail[1] = true mail[0] end |
#size ⇒ Object
Returns the number of mails in this mailbox
14 15 16 |
# File 'lib/waw/tools/mail/mailbox.rb', line 14 def size @mails.size end |