diff --git a/lib/apex/encoder/igate_tcp.rb b/lib/apex/encoder/igate_tcp.rb index 4011030c8114f082c242ac2781efdee661fc00f2..edd73fea87d8011bfececef73ecd4ecf487f8b28 100644 --- a/lib/apex/encoder/igate_tcp.rb +++ b/lib/apex/encoder/igate_tcp.rb @@ -56,9 +56,9 @@ module Apex path = path.split(',') - decoded_source = Apex::ImmutableEntity.from_raw(decoded_source) - decoded_destination = Apex::ImmutableEntity.from_raw(path.shift) - decoded_path = Apex::ImmutablePath.from_raw(path) + decoded_source = Apex::ImmutableEntity.from_raw(decoded_source, strict_callsign: false, strict_ssid: false) + decoded_destination = Apex::ImmutableEntity.from_raw(path.shift, strict_callsign: false, strict_ssid: false) + decoded_path = Apex::ImmutablePath.from_raw(path, strict_callsign: false, strict_ssid: false) decoded_payload = frame_so_far return Apex::ImmutableFrame.new(decoded_source, decoded_destination, decoded_path, decoded_payload) diff --git a/lib/apex/frame/immutable_entity.rb b/lib/apex/frame/immutable_entity.rb index 458dcd73da28be2b95242deae7702699a91ae0f8..bd9216463c3c69fb62ca4669632da3a20510841d 100644 --- a/lib/apex/frame/immutable_entity.rb +++ b/lib/apex/frame/immutable_entity.rb @@ -8,15 +8,15 @@ module Apex attr_reader :callsign, :ssid public - def initialize(callsign, ssid) + 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) + 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? - raise ArgumentError.new("Callsign must only contain numebers and letters") if callsign.strip.match?(/[^a-zA-Z0-9]/) + 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) @@ -27,7 +27,7 @@ module Apex end public - def self.from_raw(raw_hop) + 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 @@ -48,14 +48,14 @@ module Apex ssid = split_hop[1].to_i end - return Apex::ImmutableEntity.new(callsign, ssid) + return Apex::ImmutableEntity.new(callsign, ssid, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end public 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 Apex::ImmutableEntity.new(self.callsign, self.ssid - 1) + return Apex::ImmutableEntity.new(self.callsign, self.ssid - 1, strict_callsign: false, strict_ssid: false) end public diff --git a/lib/apex/frame/immutable_hop.rb b/lib/apex/frame/immutable_hop.rb index 4645b8197df71b35677df2f4d4f1b984724d4866..36137655d5cc1fe7e6e4b6d0588a52e2590b9458 100644 --- a/lib/apex/frame/immutable_hop.rb +++ b/lib/apex/frame/immutable_hop.rb @@ -7,18 +7,18 @@ module Apex include Hop public - def initialize(callsign, ssid, seen) + 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) + super(callsign, ssid, strict_callsign: strict_callsign, strict_ssid: strict_ssid) @seen = seen end public - def self.from_raw(raw_hop) + 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 @@ -33,7 +33,7 @@ module Apex seen = false end - raise ArgumentError.new("Hops can only contain letters, numbers and dashes. Hop: " + hop) if hop.strip.match?(/[^a-zA-Z0-9\-]/) + 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 @@ -46,7 +46,7 @@ module Apex ssid = split_hop[1].to_i end - return Apex::ImmutableHop.new(callsign, ssid, seen) + return Apex::ImmutableHop.new(callsign, ssid, seen, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end public @@ -56,14 +56,14 @@ module Apex public def toggle_seen - return Apex::ImmutableHop.new(self.callsign, self.ssid, !self.seen?) + return Apex::ImmutableHop.new(self.callsign, self.ssid, !self.seen?, strict_callsign: false, strict_ssid: false) end public 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 Apex::ImmutableHop.new(self.callsign, self.ssid - 1, self.seen?) + return Apex::ImmutableHop.new(self.callsign, self.ssid - 1, self.seen?, strict_callsign: false, strict_ssid: false) end public diff --git a/lib/apex/frame/immutable_path.rb b/lib/apex/frame/immutable_path.rb index cce333531d8d7cdfe5843fb9868e90f3e716888c..bfd90c3fe46b48004251753279604d3259d97c50 100644 --- a/lib/apex/frame/immutable_path.rb +++ b/lib/apex/frame/immutable_path.rb @@ -23,7 +23,7 @@ module Apex end public - def self.from_raw(raw_path) + def self.from_raw(raw_path, strict_callsign: true, strict_ssid: true) raise ArgumentError.new("raw_path can not be nil") if raw_path.nil? if raw_path.kind_of? String @@ -43,7 +43,7 @@ module Apex if hop.kind_of? Apex::Hop new_hop = hop else - new_hop = Apex::ImmutableHop.from_raw(hop) + new_hop = Apex::ImmutableHop.from_raw(hop, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end new_path_array << new_hop end diff --git a/spec/apex/frame/path_spec.rb b/spec/apex/frame/path_spec.rb index 9ab4efb0bab966f1c90175084b936ee51d279130..003bf0adba3fdd8b26ab5a9674b85b361a819c4f 100644 --- a/spec/apex/frame/path_spec.rb +++ b/spec/apex/frame/path_spec.rb @@ -70,10 +70,11 @@ describe Apex::Path do context "Given two hops where the first is unseen and second is seen" do hop1 = Apex::ImmutableHop.new("WI2ARD", 4, false) hop2 = Apex::ImmutableHop.new("K3TXD", 0, true) - it "throws an ArgumentError" do - expect { + it "instantiates a path" do path = Apex::ImmutablePath.new(hop1, hop2) - }.to raise_error(ArgumentError) + expect(path).to_not be_nil + expect(path).to be_kind_of(Apex::ImmutablePath) + expect(path).to be_kind_of(Apex::Path) end end end