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.



72
73
74
75
76
# File 'lib/multipart_parser/reader.rb', line 72

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

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#mimeObject

Returns the value of attribute mime.



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

def mime
  @mime
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#emit_data(data) ⇒ Object

Calls the data callback with the given data



79
80
81
# File 'lib/multipart_parser/reader.rb', line 79

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

#emit_endObject

Calls the end callback



84
85
86
# File 'lib/multipart_parser/reader.rb', line 84

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.



91
92
93
# File 'lib/multipart_parser/reader.rb', line 91

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.



97
98
99
# File 'lib/multipart_parser/reader.rb', line 97

def on_end(&callback)
  @end_callback = callback
end