Class: AgentClientProtocol::ProtocolVersion
- Inherits:
-
Object
- Object
- AgentClientProtocol::ProtocolVersion
- Includes:
- Comparable
- Defined in:
- lib/agent_client_protocol/protocol_version.rb
Constant Summary collapse
- V0 =
0- V1 =
1- LATEST =
V1- MAX_VALUE =
65_535
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(value) ⇒ ProtocolVersion
constructor
A new instance of ProtocolVersion.
- #to_h ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ ProtocolVersion
Returns a new instance of ProtocolVersion.
14 15 16 17 18 19 20 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 14 def initialize(value) unless value.is_a?(Integer) && value >= 0 && value <= MAX_VALUE raise ArgumentError, "protocol version must be an Integer between 0 and #{MAX_VALUE}" end @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
12 13 14 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 12 def value @value end |
Class Method Details
.parse(raw) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 22 def self.parse(raw) case raw when Integer new(raw) when String # ACP legacy behavior: old string versions map to protocol version 0. new(V0) else raise ArgumentError, "protocol version must be an Integer or String" end end |
Instance Method Details
#<=>(other) ⇒ Object
34 35 36 37 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 34 def <=>(other) other_value = other.is_a?(ProtocolVersion) ? other.value : other value <=> other_value end |
#==(other) ⇒ Object
39 40 41 42 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 39 def ==(other) other_value = other.is_a?(ProtocolVersion) ? other.value : other value == other_value end |
#to_h ⇒ Object
48 49 50 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 48 def to_h value end |
#to_i ⇒ Object
44 45 46 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 44 def to_i value end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/agent_client_protocol/protocol_version.rb', line 52 def to_s value.to_s end |