Class: Verizon::Header

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/models/header.rb

Overview

The header of the DENM PDU.

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(protocol_version = nil, message_id = nil, station_id = nil) ⇒ Header

Returns a new instance of Header.



43
44
45
46
47
# File 'lib/verizon/models/header.rb', line 43

def initialize(protocol_version = nil, message_id = nil, station_id = nil)
  @protocol_version = protocol_version
  @message_id = message_id
  @station_id = station_id
end

Instance Attribute Details

#message_idMessageIdEnum

The type of ITIS message (typically 1 for DENM).

Returns:



18
19
20
# File 'lib/verizon/models/header.rb', line 18

def message_id
  @message_id
end

#protocol_versionProtocolVersionEnum

The protocol version of the DENM.

Returns:



14
15
16
# File 'lib/verizon/models/header.rb', line 14

def protocol_version
  @protocol_version
end

#station_idInteger

The station identifier of the ITS-S.

Returns:

  • (Integer)


22
23
24
# File 'lib/verizon/models/header.rb', line 22

def station_id
  @station_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/verizon/models/header.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  protocol_version =
    hash.key?('protocolVersion') ? hash['protocolVersion'] : nil
  message_id = hash.key?('messageId') ? hash['messageId'] : nil
  station_id = hash.key?('stationId') ? hash['stationId'] : nil

  # Create object from extracted values.
  Header.new(protocol_version,
             message_id,
             station_id)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/verizon/models/header.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['protocol_version'] = 'protocolVersion'
  @_hash['message_id'] = 'messageId'
  @_hash['station_id'] = 'stationId'
  @_hash
end

.nullablesObject

An array for nullable fields



39
40
41
# File 'lib/verizon/models/header.rb', line 39

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
# File 'lib/verizon/models/header.rb', line 34

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Header | Hash)

    value against the validation is performed.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/verizon/models/header.rb', line 67

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.protocol_version,
                            ->(val) { ProtocolVersionEnum.validate(val) }) and
        APIHelper.valid_type?(value.message_id,
                              ->(val) { MessageIdEnum.validate(val) }) and
        APIHelper.valid_type?(value.station_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['protocolVersion'],
                          ->(val) { ProtocolVersionEnum.validate(val) }) and
      APIHelper.valid_type?(value['messageId'],
                            ->(val) { MessageIdEnum.validate(val) }) and
      APIHelper.valid_type?(value['stationId'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



99
100
101
102
103
# File 'lib/verizon/models/header.rb', line 99

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} protocol_version: #{@protocol_version.inspect}, message_id:"\
  " #{@message_id.inspect}, station_id: #{@station_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



92
93
94
95
96
# File 'lib/verizon/models/header.rb', line 92

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} protocol_version: #{@protocol_version}, message_id: #{@message_id},"\
  " station_id: #{@station_id}>"
end