Class: Ax25::ImmutableEntity
- Inherits:
-
Object
- Object
- Ax25::ImmutableEntity
- Includes:
- Entity
- Defined in:
- lib/ax25/frame/immutable_entity.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callsign ⇒ Object
readonly
Returns the value of attribute callsign.
-
#ssid ⇒ Object
readonly
Returns the value of attribute ssid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #decrement_ssid ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(callsign, ssid, strict_callsign: true, strict_ssid: true) ⇒ ImmutableEntity
constructor
A new instance of ImmutableEntity.
- #to_s ⇒ Object
Constructor Details
#initialize(callsign, ssid, strict_callsign: true, strict_ssid: true) ⇒ ImmutableEntity
Returns a new instance of ImmutableEntity.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ax25/frame/immutable_entity.rb', line 11 def initialize(callsign, ssid, strict_callsign: true, strict_ssid: true) raise ArgumentError.new("callsign can not be nil") if callsign.nil? raise ArgumentError.new("callsign must be a String") if not callsign.kind_of? String raise ArgumentError.new("ssid must be an Integer.") if (not ssid.nil?) && (not ssid.kind_of? Integer) raise ArgumentError.new("ssid must be a value between 0 (inclusive) and 15 (inclusive): #{callsign}-#{ssid}") if (not ssid.nil?) && (ssid < 0 || ssid > 15) && (strict_ssid) raise ArgumentError.new("Callsign can not be an empty string") if callsign.empty? && strict_callsign raise ArgumentError.new("Callsign must only contain numebers and letters") if callsign.strip.match?(/[^a-zA-Z0-9]/) && (strict_callsign) @callsign = callsign.strip.upcase.freeze if (ssid.nil?) || (ssid.eql? 0) @ssid = nil else @ssid = ssid end end |
Instance Attribute Details
#callsign ⇒ Object (readonly)
Returns the value of attribute callsign.
8 9 10 |
# File 'lib/ax25/frame/immutable_entity.rb', line 8 def callsign @callsign end |
#ssid ⇒ Object (readonly)
Returns the value of attribute ssid.
8 9 10 |
# File 'lib/ax25/frame/immutable_entity.rb', line 8 def ssid @ssid end |
Class Method Details
.from_raw(raw_hop, strict_callsign: true, strict_ssid: true) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ax25/frame/immutable_entity.rb', line 30 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 hop = raw_hop.dup raise ArgumentError.new("Hops can only contain letters, numbers and dashes") 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::ImmutableEntity.new(callsign, ssid, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end |
Instance Method Details
#==(other) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ax25/frame/immutable_entity.rb', line 69 def ==(other) return false if other.nil? return false if not other.respond_to? :callsign return false if not other.respond_to? :ssid return false if not self.callsign.eql? other.callsign return false if not self.ssid.eql? other.ssid return true end |
#decrement_ssid ⇒ Object
55 56 57 58 59 |
# File 'lib/ax25/frame/immutable_entity.rb', line 55 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::ImmutableEntity.new(self.callsign, self.ssid - 1, strict_callsign: false, strict_ssid: false) end |
#eql?(other) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/ax25/frame/immutable_entity.rb', line 62 def eql?(other) raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Ax25::Entity return self == other end |
#to_s ⇒ Object
81 82 83 84 85 |
# File 'lib/ax25/frame/immutable_entity.rb', line 81 def to_s ret_val = self.callsign.dup ret_val << ("-" + self.ssid.to_s) if not self.ssid.nil? return ret_val end |