Class: Ax25::ImmutableHop
- Inherits:
-
ImmutableEntity
- Object
- ImmutableEntity
- Ax25::ImmutableHop
- Includes:
- Hop
- Defined in:
- lib/ax25/frame/immutable_hop.rb
Instance Attribute Summary
Attributes included from Entity
Attributes inherited from ImmutableEntity
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #decrement_ssid ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(callsign, ssid, seen, strict_callsign: true, strict_ssid: true) ⇒ ImmutableHop
constructor
A new instance of ImmutableHop.
- #seen? ⇒ Boolean
- #to_s ⇒ Object
- #toggle_seen ⇒ Object
Constructor Details
permalink #initialize(callsign, ssid, seen, strict_callsign: true, strict_ssid: true) ⇒ ImmutableHop
Returns a new instance of ImmutableHop.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ax25/frame/immutable_hop.rb', line 10 def initialize(callsign, ssid, seen, strict_callsign: true, strict_ssid: true) raise ArgumentError.new("seen can not be nil") if seen.nil? raise ArgumentError.new("seen must be a Boolean") if not (!!seen == seen) super(callsign, ssid, strict_callsign: strict_callsign, strict_ssid: strict_ssid) @seen = seen end |
Class Method Details
permalink .from_raw(raw_hop, strict_callsign: true, strict_ssid: true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ax25/frame/immutable_hop.rb', line 21 def self.from_raw(raw_hop, strict_callsign: true, strict_ssid: true) raise ArgumentError.new("raw_hop can not be nil") if raw_hop.nil? callsign = nil ssid = nil seen = nil hop = raw_hop.dup if hop[-1].eql? "*" seen = true hop = hop[0..-2] else seen = false end raise ArgumentError.new("Hops can only contain letters, numbers and dashes. Hop: #{hop.to_s}") if hop.strip.match?(/[^a-zA-Z0-9\-]/) && strict_callsign if not hop.include? "-" ssid = nil callsign = hop.strip else split_hop = hop.strip.split("-") raise ArgumentError.new("More than one hypen seen in a hop, invalid format") if split_hop.length > 2 raise ArgumentError.new("Hop format was not valid, hyphen placed at end or beginning of string") if split_hop.length <= 1 callsign = split_hop[0] ssid = split_hop[1].to_i end return Ax25::ImmutableHop.new(callsign, ssid, seen, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end |
Instance Method Details
permalink #==(other) ⇒ Object
[View source]
77 78 79 80 81 82 83 84 |
# File 'lib/ax25/frame/immutable_hop.rb', line 77 def ==(other) return false if !super(other) return false if not other.respond_to? :seen? return false if not self.seen?.eql? other.seen? return true end |
permalink #decrement_ssid ⇒ Object
63 64 65 66 67 |
# File 'lib/ax25/frame/immutable_hop.rb', line 63 def decrement_ssid raise RangeError.new("SSID can not be decremented when it is currently 0 or nil") if (self.ssid.nil?) or (self.ssid <= 0) return Ax25::ImmutableHop.new(self.callsign, self.ssid - 1, self.seen?, strict_callsign: false, strict_ssid: false) end |
permalink #eql?(other) ⇒ Boolean
70 71 72 73 74 |
# File 'lib/ax25/frame/immutable_hop.rb', line 70 def eql?(other) raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Ax25::Hop return self == other end |
permalink #seen? ⇒ Boolean
53 54 55 |
# File 'lib/ax25/frame/immutable_hop.rb', line 53 def seen? return @seen end |
permalink #to_s ⇒ Object
[View source]
87 88 89 90 91 |
# File 'lib/ax25/frame/immutable_hop.rb', line 87 def to_s ret_val = super.dup ret_val << "*" if self.seen? return ret_val end |
permalink #toggle_seen ⇒ Object
[View source]
58 59 60 |
# File 'lib/ax25/frame/immutable_hop.rb', line 58 def toggle_seen return Ax25::ImmutableHop.new(self.callsign, self.ssid, !self.seen?, strict_callsign: false, strict_ssid: false) end |