Class: Arborist::Node::Ack
- Inherits:
-
Object
- Object
- Arborist::Node::Ack
- Extended by:
- HashUtilities
- Defined in:
- lib/arborist/node/ack.rb
Overview
The inner class for the ‘ack’ operational property
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
The object’s message, :sender, :via, :time.
-
#sender ⇒ Object
readonly
The object’s message, :sender, :via, :time.
-
#time ⇒ Object
readonly
The object’s message, :sender, :via, :time.
-
#via ⇒ Object
readonly
The object’s message, :sender, :via, :time.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Construct an instance from the values in the specified
hash.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the
otherobject is an Ack with the same values. -
#description ⇒ Object
Return a string description of the acknowledgement for logging and inspection.
-
#initialize(message, sender, via: nil, time: nil) ⇒ Ack
constructor
Create a new acknowledgement.
-
#to_h ⇒ Object
Return the Ack as a Hash.
Methods included from HashUtilities
compact_hash, hash_matches, merge_recursively, stringify_keys, symbolify_keys
Constructor Details
#initialize(message, sender, via: nil, time: nil) ⇒ Ack
Create a new acknowledgement
29 30 31 32 33 34 35 36 |
# File 'lib/arborist/node/ack.rb', line 29 def initialize( , sender, via: nil, time: nil ) time ||= Time.now = @sender = sender @via = via @time = time.to_time end |
Instance Attribute Details
#message ⇒ Object (readonly)
The object’s message, :sender, :via, :time
40 41 42 |
# File 'lib/arborist/node/ack.rb', line 40 def end |
#sender ⇒ Object (readonly)
The object’s message, :sender, :via, :time
40 41 42 |
# File 'lib/arborist/node/ack.rb', line 40 def sender @sender end |
#time ⇒ Object (readonly)
The object’s message, :sender, :via, :time
40 41 42 |
# File 'lib/arborist/node/ack.rb', line 40 def time @time end |
#via ⇒ Object (readonly)
The object’s message, :sender, :via, :time
40 41 42 |
# File 'lib/arborist/node/ack.rb', line 40 def via @via end |
Class Method Details
.from_hash(hash) ⇒ Object
Construct an instance from the values in the specified hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/arborist/node/ack.rb', line 13 def self::from_hash( hash ) hash = symbolify_keys( hash ) = hash.delete( :message ) or raise ArgumentError, "Missing required ACK message" sender = hash.delete( :sender ) or raise ArgumentError, "Missing required ACK sender" if hash[:time] hash[:time] = Time.at( hash[:time] ) if hash[:time].is_a?( Numeric ) hash[:time] = Time.parse( hash[:time] ) unless hash[:time].is_a?( Time ) end return new( , sender, **hash ) end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the other object is an Ack with the same values.
65 66 67 68 |
# File 'lib/arborist/node/ack.rb', line 65 def ==( other ) return other.is_a?( self.class ) && self.to_h == other.to_h end |
#description ⇒ Object
Return a string description of the acknowledgement for logging and inspection.
44 45 46 47 48 49 50 |
# File 'lib/arborist/node/ack.rb', line 44 def description return "by %s%s -- %s" % [ self.sender, self.via ? " via #{self.via}" : '', self. ] end |
#to_h ⇒ Object
Return the Ack as a Hash.
54 55 56 57 58 59 60 61 |
# File 'lib/arborist/node/ack.rb', line 54 def to_h( * ) return { message: self., sender: self.sender, via: self.via, time: self.time.iso8601, } end |