Class: Formatters::InteropFormatter
- Inherits:
-
DictFormatter
- Object
- BasicFormatter
- DictFormatter
- Formatters::InteropFormatter
- Defined in:
- lib/formatters/interop_formatter.rb
Overview
Formatter of message into interop dictionary format
Instance Attribute Summary
Attributes inherited from BasicFormatter
Instance Method Summary collapse
-
#format_value(value) ⇒ Object
- Format value according to type ==== Parameters value
-
value to format ==== Returns value formatted as string.
-
#get_as_interop_dictionary ⇒ Object
Format message as interop dictionary ==== Returns message formatted as interop dictionary.
-
#initialize(message, msg_content_hashed = false) ⇒ InteropFormatter
constructor
- Initialization of interop dictionary formatter ==== Interop dictionary formatter arguments message
-
message to format.
-
#print ⇒ Object
Prints message formatted as interop dictionary to stdout.
Methods inherited from DictFormatter
Methods inherited from BasicFormatter
Constructor Details
#initialize(message, msg_content_hashed = false) ⇒ InteropFormatter
Initialization of interop dictionary formatter
Interop dictionary formatter arguments
- message
-
message to format
27 28 29 |
# File 'lib/formatters/interop_formatter.rb', line 27 def initialize(, msg_content_hashed=false) super(, msg_content_hashed) end |
Instance Method Details
#format_value(value) ⇒ Object
Format value according to type
Parameters
- value
-
value to format
Returns
value formatted as string
36 37 38 39 40 41 42 43 44 |
# File 'lib/formatters/interop_formatter.rb', line 36 def format_value(value) case value when Float # ab_diff = [{'content': [[-1.3, -1.2999999523162842]]}] value.round(5) else super end end |
#get_as_interop_dictionary ⇒ Object
Format message as interop dictionary
Returns
message formatted as interop dictionary
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/formatters/interop_formatter.rb', line 49 def get_as_interop_dictionary() dict_to_return = "" \ + "'redelivered': #{format_value( @message.delivery_count == 0 ? false : true )}, "\ + "'reply-to': #{format_value(@message.reply_to)}, "\ + "'subject': #{format_value(@message.subject)}, "\ + "'content-type': #{format_value(@message.content_type)}, "\ + "'id': #{format_value(@message.id)}, "\ + "'group-id': #{format_value(@message.group_id)}, "\ + "'user-id': #{format_value(@message.user_id)}, "\ + "'correlation-id': #{format_value(@message.correlation_id)}, "\ + "'priority': #{format_value(@message.priority)}, "\ + "'durable': #{format_value(@message.durable)}, "\ + "'ttl': #{format_value(@message.ttl)}, "\ + "'absolute-expiry-time': #{format_value(@message.expires)}, "\ + "'address': #{format_value(@message.address.nil? ? nil : @message.address.sub(%r{^topic://}, ''))}, "\ + "'content-encoding': #{format_value(@message.content_encoding)}, "\ + "'delivery-count': #{format_value(@message.delivery_count)}, "\ + "'first-acquirer': #{format_value(@message.first_acquirer?)}, "\ + "'group-sequence': #{format_value(@message.group_sequence)}, "\ + "'reply-to-group-id': #{format_value(@message.reply_to_group_id)}, "\ + "'to': #{format_value(@message.to)}, "\ + "'properties': #{format_value(@message.properties)}, "\ + "'content': #{ format_value(@msg_content_hashed ? StringUtils.sha1_hash(@message.body) : @message.body) }" return self.class.escape_chars("{#{dict_to_return}}") end |
#print ⇒ Object
Prints message formatted as interop dictionary to stdout
80 81 82 83 |
# File 'lib/formatters/interop_formatter.rb', line 80 def print() # Print formatted message to stdout puts get_as_interop_dictionary() end |