Class: SumologicCloudSyslog::StructuredData

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic_cloud_syslog/protocol.rb

Overview

Structured data field

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ StructuredData

Returns a new instance of StructuredData.



87
88
89
90
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 87

def initialize(id)
  @id = id
  @data = {}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



85
86
87
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 85

def data
  @data
end

#idObject

Returns the value of attribute id.



85
86
87
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 85

def id
  @id
end

Instance Method Details

#assembleObject

Format data structured data to

id k=“v” …


94
95
96
97
98
99
100
101
102
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 94

def assemble
  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_sObject



104
105
106
# File 'lib/sumologic_cloud_syslog/protocol.rb', line 104

def to_s
  assemble
end