Class: Verizon::Generic

Inherits:
BaseModel
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_type
  @message_format = message_format
  @payload = payload
end

Instance Attribute Details

#message_formatString

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.

Returns:

  • (String)


29
30
31
# File 'lib/verizon/models/generic.rb', line 29

def message_format
  @message_format
end

#message_typeString

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.

Returns:

  • (String)


20
21
22
# File 'lib/verizon/models/generic.rb', line 20

def message_type
  @message_type
end

#payloadString

The base64 encoded message.

Returns:

  • (String)


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.
  message_type = hash.key?('messageType') ? hash['messageType'] : nil
  message_format = hash.key?('messageFormat') ? hash['messageFormat'] : nil
  payload = hash.key?('payload') ? hash['payload'] : nil

  # Create object from extracted values.
  Generic.new(message_type: message_type,
              message_format: message_format,
              payload: payload)
end

.namesObject

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

.nullablesObject

An array for nullable fields



50
51
52
# File 'lib/verizon/models/generic.rb', line 50

def self.nullables
  []
end

.optionalsObject

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.

Parameters:

  • The (Generic | Hash)

    value against the validation is performed.



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.message_type,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.message_format,
                              ->(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

#inspectObject

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_sObject

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