Class: MultipartParser::Reader::Part

Inherits:
Object
  • Object
show all
Defined in:
lib/multipart_parser/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePart

Returns a new instance of Part.



69
70
71
72
73
# File 'lib/multipart_parser/reader.rb', line 69

def initialize
  @headers = {}
  @data_callback = nil
  @end_callback = nil
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



67
68
69
# File 'lib/multipart_parser/reader.rb', line 67

def filename
  @filename
end

#headersObject

Returns the value of attribute headers.



67
68
69
# File 'lib/multipart_parser/reader.rb', line 67

def headers
  @headers
end

#mimeObject

Returns the value of attribute mime.



67
68
69
# File 'lib/multipart_parser/reader.rb', line 67

def mime
  @mime
end

#nameObject

Returns the value of attribute name.



67
68
69
# File 'lib/multipart_parser/reader.rb', line 67

def name
  @name
end

Instance Method Details

#emit_data(data) ⇒ Object

Calls the data callback with the given data



76
77
78
# File 'lib/multipart_parser/reader.rb', line 76

def emit_data(data)
  @data_callback.call(data) unless @data_callback.nil?
end

#emit_endObject

Calls the end callback



81
82
83
# File 'lib/multipart_parser/reader.rb', line 81

def emit_end
  @end_callback.call unless @end_callback.nil?
end

#on_data(&callback) ⇒ Object

Sets a block to be called when part data is read. The block should take one parameter, namely the read data.



88
89
90
# File 'lib/multipart_parser/reader.rb', line 88

def on_data(&callback)
  @data_callback = callback
end

#on_end(&callback) ⇒ Object

Sets a block to be called when all data for the part has been read.



94
95
96
# File 'lib/multipart_parser/reader.rb', line 94

def on_end(&callback)
  @end_callback = callback
end