Class: Verizon::Generic
- Defined in:
- lib/verizon/models/generic.rb
Overview
Custom message which is defined by the user and can support “any” message type or format. Note: ETX prefers the j2735 or the j2735_gr encoding and only vendor specific message types are allowed to be published in different message formats.
Instance Attribute Summary collapse
-
#message_format ⇒ String
The encoding of the message (e.g. j2735, protobuf, json, Avro, etc.).
-
#message_type ⇒ String
The type of message.
-
#payload ⇒ String
The base64 encoded message.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(message_type:, message_format:, payload:) ⇒ Generic
constructor
A new instance of Generic.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(message_type:, message_format:, payload:) ⇒ Generic
Returns a new instance of Generic.
54 55 56 57 58 |
# File 'lib/verizon/models/generic.rb', line 54 def initialize(message_type:, message_format:, payload:) @message_type = @message_format = @payload = payload end |
Instance Attribute Details
#message_format ⇒ String
The encoding of the message (e.g. j2735, protobuf, json, Avro, etc.). If the message is encapsulated within a GeoRoutedMsg protocol buffer wrapper, append _gr to the message format (e.g. j2735 => j2735_gr). Note: ETX prefers the j2735 or the j2735_gr encoding and only vendor specific message types are allowed to be published in different message formats.
29 30 31 |
# File 'lib/verizon/models/generic.rb', line 29 def @message_format end |
#message_type ⇒ String
The type of message. This can be any of the standard V2X messages specified in the SAE J2735 standard (e.g. BSM, PSM, RSA, TIM, MAP, SPAT, etc.), or it can be a vendor specific message type that is not defined by the standard.
20 21 22 |
# File 'lib/verizon/models/generic.rb', line 20 def @message_type end |
#payload ⇒ String
The base64 encoded message.
33 34 35 |
# File 'lib/verizon/models/generic.rb', line 33 def payload @payload end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/verizon/models/generic.rb', line 61 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. = hash.key?('messageType') ? hash['messageType'] : nil = hash.key?('messageFormat') ? hash['messageFormat'] : nil payload = hash.key?('payload') ? hash['payload'] : nil # Create object from extracted values. Generic.new(message_type: , message_format: , payload: payload) end |
.names ⇒ Object
A mapping from model property names to API property names.
36 37 38 39 40 41 42 |
# File 'lib/verizon/models/generic.rb', line 36 def self.names @_hash = {} if @_hash.nil? @_hash['message_type'] = 'messageType' @_hash['message_format'] = 'messageFormat' @_hash['payload'] = 'payload' @_hash end |
.nullables ⇒ Object
An array for nullable fields
50 51 52 |
# File 'lib/verizon/models/generic.rb', line 50 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
45 46 47 |
# File 'lib/verizon/models/generic.rb', line 45 def self.optionals [] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/verizon/models/generic.rb', line 77 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value., ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value., ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.payload, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['messageType'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['messageFormat'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['payload'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
109 110 111 112 113 |
# File 'lib/verizon/models/generic.rb', line 109 def inspect class_name = self.class.name.split('::').last "<#{class_name} message_type: #{@message_type.inspect}, message_format:"\ " #{@message_format.inspect}, payload: #{@payload.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
102 103 104 105 106 |
# File 'lib/verizon/models/generic.rb', line 102 def to_s class_name = self.class.name.split('::').last "<#{class_name} message_type: #{@message_type}, message_format: #{@message_format},"\ " payload: #{@payload}>" end |