Class: Sisimai::Mail::STDIN
- Inherits:
-
Object
- Object
- Sisimai::Mail::STDIN
- Defined in:
- lib/sisimai/mail/stdin.rb
Overview
Sisimai::Mail::STDIN is a reader for getting contents of each email from STDIN
Instance Attribute Summary collapse
-
#handle ⇒ Object
Returns the value of attribute handle.
-
#name ⇒ Object
readonly
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#path ⇒ Object
readonly
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle.
-
#size ⇒ Object
readonly
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle.
Instance Method Summary collapse
-
#initialize(stdin = $stdin) ⇒ Sisimai::Mail::STDIN
constructor
Constructor of Sisimai::Mail::STDIN.
-
#read ⇒ String
Mbox reader, works as an iterator.
Constructor Details
#initialize(stdin = $stdin) ⇒ Sisimai::Mail::STDIN
Constructor of Sisimai::Mail::STDIN
15 16 17 18 19 20 21 22 |
# File 'lib/sisimai/mail/stdin.rb', line 15 def initialize(stdin = $stdin) raise 'is not an IO object' if stdin.is_a?(IO) == false @path = '<STDIN>' @size = nil @offset = 0 @handle = stdin end |
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
10 11 12 |
# File 'lib/sisimai/mail/stdin.rb', line 10 def handle @handle end |
#name ⇒ Object (readonly)
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle
9 10 11 |
# File 'lib/sisimai/mail/stdin.rb', line 9 def name @name end |
#offset ⇒ Object
Returns the value of attribute offset.
10 11 12 |
# File 'lib/sisimai/mail/stdin.rb', line 10 def offset @offset end |
#path ⇒ Object (readonly)
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle
9 10 11 |
# File 'lib/sisimai/mail/stdin.rb', line 9 def path @path end |
#size ⇒ Object (readonly)
:path [String] Fixed string “<STDIN>” :size [Integer] Data size which has been read :offset [Integer] The number of emails which have neen read :handle [IO::File] File handle
9 10 11 |
# File 'lib/sisimai/mail/stdin.rb', line 9 def size @size end |
Instance Method Details
#read ⇒ String
Mbox reader, works as an iterator.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sisimai/mail/stdin.rb', line 26 def read readhandle = self.handle readbuffer = '' if readhandle return nil if readhandle.closed? end begin readhandle = STDIN if readhandle.nil? while r = readhandle.gets break if readbuffer.size > 0 && r.start_with?('From ') readbuffer << r end ensure readhandle.close end self.size += readbuffer.size self.offset += 1 return readbuffer end |