Class: Imap::Backup::Serializer::MboxEnumerator
- Inherits:
-
Object
- Object
- Imap::Backup::Serializer::MboxEnumerator
- Defined in:
- lib/imap/backup/serializer/mbox_enumerator.rb
Instance Attribute Summary collapse
-
#mbox_pathname ⇒ Object
readonly
Returns the value of attribute mbox_pathname.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(mbox_pathname) ⇒ MboxEnumerator
constructor
A new instance of MboxEnumerator.
Constructor Details
#initialize(mbox_pathname) ⇒ MboxEnumerator
Returns a new instance of MboxEnumerator.
7 8 9 |
# File 'lib/imap/backup/serializer/mbox_enumerator.rb', line 7 def initialize(mbox_pathname) @mbox_pathname = mbox_pathname end |
Instance Attribute Details
#mbox_pathname ⇒ Object (readonly)
Returns the value of attribute mbox_pathname.
5 6 7 |
# File 'lib/imap/backup/serializer/mbox_enumerator.rb', line 5 def mbox_pathname @mbox_pathname end |
Instance Method Details
#each ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/imap/backup/serializer/mbox_enumerator.rb', line 11 def each return enum_for(:each) if !block_given? File.open(mbox_pathname, "rb") do |f| lines = [] loop do line = f.gets break if !line if line.start_with?("From ") yield lines.join if lines.count.positive? lines = [line] else lines << line end end yield lines.join if lines.count.positive? end end |