class CloudEvents::Format::Multi
A convenience formatter that checks multiple formats for one capable of handling the given input.
Attributes
formats[R]
The formats to check, in order.
@return [Array<Format>]
Public Class Methods
new(formats = [], &result_checker)
click to toggle source
Create a multi format.
@param formats [Array<Format>] An array of formats to check in order @param result_checker [Proc] An optional block that determines whether
a result provided by a format is acceptable. The block takes the format's result as an argument, and returns either the result to indicate acceptability, or `nil` to indicate not.
# File lib/cloud_events/format.rb, line 216 def initialize formats = [], &result_checker @formats = formats @result_checker = result_checker end
Public Instance Methods
decode_data(**kwargs)
click to toggle source
Implements {Format#decode_data}
# File lib/cloud_events/format.rb, line 255 def decode_data **kwargs @formats.each do |elem| result = elem.decode_data(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end
decode_event(**kwargs)
click to toggle source
Implements {Format#decode_event}
# File lib/cloud_events/format.rb, line 231 def decode_event **kwargs @formats.each do |elem| result = elem.decode_event(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end
encode_data(**kwargs)
click to toggle source
Implements {Format#encode_data}
# File lib/cloud_events/format.rb, line 267 def encode_data **kwargs @formats.each do |elem| result = elem.encode_data(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end
encode_event(**kwargs)
click to toggle source
Implements {Format#encode_event}
# File lib/cloud_events/format.rb, line 243 def encode_event **kwargs @formats.each do |elem| result = elem.encode_event(**kwargs) result = @result_checker.call result if @result_checker return result if result end nil end