Class: SyslogTls::StructuredData
- Inherits:
-
Object
- Object
- SyslogTls::StructuredData
- Defined in:
- lib/syslog_tls/protocol.rb
Overview
Structured data field
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#assemble ⇒ Object
Format data structured data to [id k=“v” …].
-
#initialize(id) ⇒ StructuredData
constructor
A new instance of StructuredData.
- #to_s ⇒ Object
Constructor Details
#initialize(id) ⇒ StructuredData
Returns a new instance of StructuredData.
89 90 91 92 |
# File 'lib/syslog_tls/protocol.rb', line 89 def initialize(id) @id = id @data = {} end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
87 88 89 |
# File 'lib/syslog_tls/protocol.rb', line 87 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
87 88 89 |
# File 'lib/syslog_tls/protocol.rb', line 87 def id @id end |
Instance Method Details
#assemble ⇒ Object
Format data structured data to
- id k=“v” …
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/syslog_tls/protocol.rb', line 96 def assemble return NIL_VALUE unless id parts = [id] data.each do |k, v| # Characters ", ] and \ must be escaped to prevent any parsing errors v = v.gsub(/(\"|\]|\\)/) { |match| '\\' + match } parts << "#{k}=\"#{v}\"" end "[#{parts.join(' ')}]" end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/syslog_tls/protocol.rb', line 107 def to_s assemble end |