diff --git a/lib/apex.rb b/lib/apex.rb index 7318de0ffd9bc6bfbe23478b8da443b9890d4615..0b2e392f890b4587d45079da165020478891bcf7 100644 --- a/lib/apex.rb +++ b/lib/apex.rb @@ -1,2 +1,3 @@ -require 'apex/aprs_kiss' -require 'apex/igate_tcp' \ No newline at end of file +require 'apex/encoder' +require 'apex/frame' +require 'apex/app_info' diff --git a/lib/apex/encoder/aprs_kiss.rb b/lib/apex/encoder/aprs_kiss.rb index d1114ce659c689e0f5a78c0418ab548249da3fee..ce9a63b80634ea3f73f7af2f09c3ddfd37a5b448 100644 --- a/lib/apex/encoder/aprs_kiss.rb +++ b/lib/apex/encoder/aprs_kiss.rb @@ -34,12 +34,12 @@ module Apex frame_map = @data_stream.read return nil if frame_map.nil? - source = Apex::Frame::Entity.from_raw(frame_map[:source]) - destination = Apex::Frame::Entity.from_raw(frame_map[:destination]) + source = Apex::Entity.from_raw(frame_map[:source]) + destination = Apex::Entity.from_raw(frame_map[:destination]) - path = Apex::Frame::Path.from_raw(frame_map[:path]) + path = Apex::Path.from_raw(frame_map[:path]) - return Apex::Frame::Frame.new(source, destination, path, frame_map[:payload]) + return Apex::Frame.new(source, destination, path, frame_map[:payload]) end public diff --git a/lib/apex/encoder/igate_tcp.rb b/lib/apex/encoder/igate_tcp.rb index beff68bdf7720b4a68dd500f7054fcb3a25ae5c3..ea710d7fc769dd1c4b73870bd65d333191053f5b 100644 --- a/lib/apex/encoder/igate_tcp.rb +++ b/lib/apex/encoder/igate_tcp.rb @@ -55,12 +55,12 @@ module Apex path = path.split(',') - decoded_source = Apex::Frame::Entity.from_raw(decoded_source) - decoded_destination = Apex::Frame::Entity.from_raw(path.shift) - decoded_path = Apex::Frame::Path.from_raw(path) + decoded_source = Apex::Entity.from_raw(decoded_source) + decoded_destination = Apex::Entity.from_raw(path.shift) + decoded_path = Apex::Path.from_raw(path) decoded_payload = frame_so_far - return Apex::Frame::Frame.new(decoded_source, decoded_destination, decoded_path, decoded_payload) + return Apex::Frame.new(decoded_source, decoded_destination, decoded_path, decoded_payload) end private diff --git a/lib/apex/frame.rb b/lib/apex/frame.rb index 123141ee812e4f794d6056eae4691475a7e3940f..240247a71d13f1ce68edec0f2b052c310f02e473 100644 --- a/lib/apex/frame.rb +++ b/lib/apex/frame.rb @@ -4,4 +4,3 @@ require 'apex/frame/hop' require 'apex/frame/path' require 'apex/frame/unpathed_frame' require 'apex/frame/path_agnostic_frame' -require 'apex/frame/frame' diff --git a/lib/apex/frame/entity.rb b/lib/apex/frame/entity.rb index ad09e141fb26cbb40e981bc172acf8e9948d8a2c..1552f33cd37245c9fdc75dd669e00e11c9923a91 100644 --- a/lib/apex/frame/entity.rb +++ b/lib/apex/frame/entity.rb @@ -1,85 +1,83 @@ module Apex - module Frame + public + class Entity + attr_reader :callsign, :ssid + public - class Entity - attr_reader :callsign, :ssid - - public - def initialize(callsign, ssid) - 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)") if (not ssid.nil?) && (ssid < 0 || ssid > 15) - 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]/) - - @callsign = callsign.strip.upcase.freeze - if (ssid.nil?) || (ssid.eql? 0) - @ssid = nil - else - @ssid = ssid - end - end + def initialize(callsign, ssid) + raise ArgumentError.new("callsign can not be nil") if callsign.nil? - public - def self.from_raw(raw_hop) - raise ArgumentError.new("raw_hop can not be nil") if raw_hop.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) - callsign = nil - ssid = nil + raise ArgumentError.new("ssid must be a value between 0 (inclusive) and 15 (inclusive)") if (not ssid.nil?) && (ssid < 0 || ssid > 15) + 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]/) - hop = raw_hop.dup + @callsign = callsign.strip.upcase.freeze + if (ssid.nil?) || (ssid.eql? 0) + @ssid = nil + else + @ssid = ssid + end + end - raise ArgumentError.new("Hops can only contain letters, numbers and dashes") if hop.strip.match?(/[^a-zA-Z0-9\-]/) + public + def self.from_raw(raw_hop) + raise ArgumentError.new("raw_hop can not be nil") if raw_hop.nil? - 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 + callsign = nil + ssid = nil - return Apex::Frame::Entity.new(callsign, ssid) - end + hop = raw_hop.dup - 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) + raise ArgumentError.new("Hops can only contain letters, numbers and dashes") if hop.strip.match?(/[^a-zA-Z0-9\-]/) - return Apex::Frame::Entity.new(self.callsign, self.ssid - 1) + 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 - public - def eql?(other) - raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Apex::Frame::Entity + return Apex::Entity.new(callsign, ssid) + end - return self == other - 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) - public - def ==(other) - return false if other.nil? - return false if not other.respond_to? :callsign - return false if not other.respond_to? :ssid + return Apex::Entity.new(self.callsign, self.ssid - 1) + end - return false if not self.callsign.eql? other.callsign - return false if not self.ssid.eql? other.ssid + public + def eql?(other) + raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Apex::Entity - return true - end + return self == other + end - public - def to_s - ret_val = self.callsign.dup - ret_val << ("-" + self.ssid.to_s) if not self.ssid.nil? - return ret_val - end + public + 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 + + public + def to_s + ret_val = self.callsign.dup + ret_val << ("-" + self.ssid.to_s) if not self.ssid.nil? + return ret_val end end end diff --git a/lib/apex/frame/frame.rb b/lib/apex/frame/frame.rb index 8ac15420e450657910a3e8865d0e7ba6d04df40c..c77eeca1922f1adc90a14e3954ef19a7f79d3d32 100644 --- a/lib/apex/frame/frame.rb +++ b/lib/apex/frame/frame.rb @@ -1,51 +1,49 @@ require 'apex/frame/unpathed_frame' module Apex - module Frame - public - class Frame < Apex::Frame::UnpathedFrame - attr_accessor :path + public + class Frame < Apex::UnpathedFrame + attr_accessor :path - protected - def initialize(source, destination, path, payload) - raise ArgumentError.new("path argument can not be nil") if path.nil? - raise ArgumentError.new("path argument must be a Path, but found: " + path.class.to_s) if not path.kind_of? Apex::Frame::Path + protected + def initialize(source, destination, path, payload) + raise ArgumentError.new("path argument can not be nil") if path.nil? + raise ArgumentError.new("path argument must be a Path, but found: " + path.class.to_s) if not path.kind_of? Apex::Path - super(source, destination, payload) + super(source, destination, payload) - @path = path - end + @path = path + end - public - def eql?(other) - raise ArgumentError.new("The argument can not be a UnpathedFrame or a PathAgnosticFrame") if ((other.instance_of? UnpathedFrame) || (other.instance_of? PathAgnosticFrame)) - raise ArgumentError.new("The argument must be of type Frame (or a child class).") if not other.kind_of? Frame + public + def eql?(other) + raise ArgumentError.new("The argument can not be a UnpathedFrame or a PathAgnosticFrame") if ((other.instance_of? UnpathedFrame) || (other.instance_of? PathAgnosticFrame)) + raise ArgumentError.new("The argument must be of type Frame (or a child class).") if not other.kind_of? Frame - return self == other - end + return self == other + end - public - def ==(other) - return false if not super(other) + public + def ==(other) + return false if not super(other) - return false if not other.respond_to? :path + return false if not other.respond_to? :path - if self.path.eql? other.path - return true - else - return false - end + if self.path.eql? other.path + return true + else + return false end + end - public - def hash - return [super, self.path].hash - end + public + def hash + return [super, self.path].hash + end - public - def path_agnostic_identity - return PathAgnosticFrame.new(self.source, self.destination, self.path, self.payload) - end + public + def path_agnostic_identity + return PathAgnosticFrame.new(self.source, self.destination, self.path, self.payload) end end end diff --git a/lib/apex/frame/hop.rb b/lib/apex/frame/hop.rb index 1d5996b5106ec61bb91b648fbb2b60d71fb64b96..b606e53e495534d474afd4e42df3779ced8ed721 100644 --- a/lib/apex/frame/hop.rb +++ b/lib/apex/frame/hop.rb @@ -1,87 +1,85 @@ module Apex - module Frame + public + class Hop < Apex::Entity + attr_reader :seen + public - class Hop < Apex::Frame::Entity - attr_reader :seen + def initialize(callsign, ssid, seen) - public - def initialize(callsign, ssid, seen) + raise ArgumentError.new("seen can not be nil") if seen.nil? + raise ArgumentError.new("seen must be a Boolean") if not (!!seen == seen) - 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) + @seen = seen + end - @seen = seen + public + def self.from_raw(raw_hop) + 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 - public - def self.from_raw(raw_hop) - raise ArgumentError.new("raw_hop can not be nil") if raw_hop.nil? + raise ArgumentError.new("Hops can only contain letters, numbers and dashes. Hop: " + hop) if hop.strip.match?(/[^a-zA-Z0-9\-]/) - callsign = nil + if not hop.include? "-" 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) if hop.strip.match?(/[^a-zA-Z0-9\-]/) - - 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 Apex::Frame::Hop.new(callsign, ssid, seen) + 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 - public - def toggle_seen - return Apex::Frame::Hop.new(self.callsign, self.ssid, !self.seen) - end + return Apex::Hop.new(callsign, ssid, seen) + 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) + public + def toggle_seen + return Apex::Hop.new(self.callsign, self.ssid, !self.seen) + end - return Apex::Frame::Hop.new(self.callsign, self.ssid - 1, self.seen) - 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) - public - def eql?(other) - raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Apex::Frame::Hop + return Apex::Hop.new(self.callsign, self.ssid - 1, self.seen) + end - return self == other - end + public + def eql?(other) + raise ArgumentError.new("The argument must be of type Hop (or a child class).") if not other.kind_of? Apex::Hop - public - def ==(other) - return false if !super(other) + return self == other + end - return false if not other.respond_to? :seen - return false if not self.seen.eql? other.seen + public + def ==(other) + return false if !super(other) - return true - end + return false if not other.respond_to? :seen + return false if not self.seen.eql? other.seen - public - def to_s - ret_val = super.dup - ret_val << "*" if self.seen - return ret_val - end + return true + end + + public + def to_s + ret_val = super.dup + ret_val << "*" if self.seen + return ret_val end end end diff --git a/lib/apex/frame/path.rb b/lib/apex/frame/path.rb index 0cf4979ce743dfe3f7f83160a5940e87a32c38d6..5ae7a78dc28c6d96bc1a515f9d6e524a4c12fde3 100644 --- a/lib/apex/frame/path.rb +++ b/lib/apex/frame/path.rb @@ -1,110 +1,108 @@ require 'apex/frame/hop' module Apex - module Frame - public - class Path - def initialize(*hops) - raise ArgumentError.new("Must be called with atleast one argument") if (hops.nil?) || (hops.length <= 0) - @path_array = [] - last_seen = true - hops.each do |hop| - raise ArgumentError.new("All arguments must not be nil: #{hops.to_s}") if (hop.nil?) - raise ArgumentError.new("All arguments must be of type Hop: #{hops.class.to_s}") if not hop.kind_of? Apex::Frame::Hop - raise ArgumentError.new("A seen hop can not follow an unseen hop") if (hop.seen) && (!last_seen) - last_seen = false if not hop.seen - @path_array << hop - end - - @path_array.freeze - freeze + public + class Path + def initialize(*hops) + raise ArgumentError.new("Must be called with atleast one argument") if (hops.nil?) || (hops.length <= 0) + @path_array = [] + last_seen = true + hops.each do |hop| + raise ArgumentError.new("All arguments must not be nil: #{hops.to_s}") if (hop.nil?) + raise ArgumentError.new("All arguments must be of type Hop: #{hops.class.to_s}") if not hop.kind_of? Apex::Hop + raise ArgumentError.new("A seen hop can not follow an unseen hop") if (hop.seen) && (!last_seen) + last_seen = false if not hop.seen + @path_array << hop end - public - def self.from_raw(raw_path) - raise ArgumentError.new("raw_path can not be nil") if raw_path.nil? - - if raw_path.kind_of? String - if raw_path.include? "," - raise ArgumentError.new("raw_path is too short") if raw_path.length < 3 - raw_path = raw_path.split(",") - else - raise ArgumentError.new("raw_path is too short") if raw_path.length < 1 - raw_path = [raw_path] - end - end - - raise ArgumentError.new("raw_path must be array-like") if not raw_path.respond_to? :[] + @path_array.freeze + freeze + end - new_path_array = [] - raw_path.each do |hop| - if hop.kind_of? Apex::Frame::Hop - new_hop = hop - else - new_hop = Apex::Frame::Hop.from_raw(hop) - end - new_path_array << new_hop + public + def self.from_raw(raw_path) + raise ArgumentError.new("raw_path can not be nil") if raw_path.nil? + + if raw_path.kind_of? String + if raw_path.include? "," + raise ArgumentError.new("raw_path is too short") if raw_path.length < 3 + raw_path = raw_path.split(",") + else + raise ArgumentError.new("raw_path is too short") if raw_path.length < 1 + raw_path = [raw_path] end - - return Apex::Frame::Path.new(*new_path_array) end - public - def each - @path_array.each do |hop| - yield(hop) + raise ArgumentError.new("raw_path must be array-like") if not raw_path.respond_to? :[] + + new_path_array = [] + raw_path.each do |hop| + if hop.kind_of? Apex::Hop + new_hop = hop + else + new_hop = Apex::Hop.from_raw(hop) end + new_path_array << new_hop end - public - def [](idx) - return @path_array[idx].dup.freeze - end + return Apex::Path.new(*new_path_array) + end - public - def length - return @path_array.length + public + def each + @path_array.each do |hop| + yield(hop) end + end - public - def eql?(other) - raise ArgumentError.new("The argument must be of type Path (or a child class).") if not other.kind_of? Path + public + def [](idx) + return @path_array[idx].dup.freeze + end - return self == other - end + public + def length + return @path_array.length + end - public - def ==(other) - return false if not other.respond_to? :[] - return false if not other.respond_to? :length - return false if not self.length.eql? other.length + public + def eql?(other) + raise ArgumentError.new("The argument must be of type Path (or a child class).") if not other.kind_of? Path - (0..self.length - 1).each do |idx| - return false if not self[idx].eql? other[idx] - end + return self == other + end - return true - end + public + def ==(other) + return false if not other.respond_to? :[] + return false if not other.respond_to? :length + return false if not self.length.eql? other.length - public - def to_s - return @path_array.join(',') + (0..self.length - 1).each do |idx| + return false if not self[idx].eql? other[idx] end - public - def to_string_array - return @path_array.map {|e| e.to_s} - end + return true + end - public - def unseen_hops - @path_array.select { |hop| !hop.seen } - end + public + def to_s + return @path_array.join(',') + end - public - def seen_hops - @path_array.select { |hop| hop.seen } - end + public + def to_string_array + return @path_array.map {|e| e.to_s} + end + + public + def unseen_hops + @path_array.select { |hop| !hop.seen } + end + + public + def seen_hops + @path_array.select { |hop| hop.seen } end end end diff --git a/lib/apex/frame/path_agnostic_frame.rb b/lib/apex/frame/path_agnostic_frame.rb index b9e9c83ba366f5406ba0933dcfe026131a866e19..d9602313ec6c1c1c6623452f3e8e91bff1a8c95d 100644 --- a/lib/apex/frame/path_agnostic_frame.rb +++ b/lib/apex/frame/path_agnostic_frame.rb @@ -1,31 +1,29 @@ module Apex - module Frame - private - class PathAgnosticFrame < Frame - protected - def initialize(source, destination, path, payload) - super(source, destination, path, payload) - end + private + class PathAgnosticFrame < Frame + protected + def initialize(source, destination, path, payload) + super(source, destination, path, payload) + end - public - def eql?(other) - return self.path_agnostic_eql? other - end + public + def eql?(other) + return self.path_agnostic_eql? other + end - public - def ==(other) - return self.path_agnostic_equality? other - end + public + def ==(other) + return self.path_agnostic_equality? other + end - public - def hash - return self.path_agnostic_hash - end + public + def hash + return self.path_agnostic_hash + end - public - def path_agnostic_identity - return self - end + public + def path_agnostic_identity + return self end end end diff --git a/lib/apex/frame/unpathed_frame.rb b/lib/apex/frame/unpathed_frame.rb index 3deddaa2c7762c7c2d7d7da23d9ac7cbbdb61be8..334641a2d365ccaeaf4bc5914e610bf2878ab422 100644 --- a/lib/apex/frame/unpathed_frame.rb +++ b/lib/apex/frame/unpathed_frame.rb @@ -1,84 +1,82 @@ module Apex - module Frame + ## + # An APXP compatible APRS frame, excluding the path data entierly. The + # UnpathedFrame and all its fields are immutable. + # + # @example Comparing frames + # orig_frame = Apex.new('WI2ARD-1', 'OMG', ['WIDE2-2' 'WIDE1-1'], 'payload goes here') + # diff_frame = Apex.new('WI2ARD-1', 'OMG', ['WIDE2-2' 'WIDE1-1'], 'different payload') + # assert not orig_frame.eql? diff_frame + public + class UnpathedFrame + attr_accessor :source, :destination, :payload + ## - # An APXP compatible APRS frame, excluding the path data entierly. The - # UnpathedFrame and all its fields are immutable. + # Creates a new frame, all fields are duplicated but and immutable. All + # fields are validated. # - # @example Comparing frames - # orig_frame = Apex::Frame.new('WI2ARD-1', 'OMG', ['WIDE2-2' 'WIDE1-1'], 'payload goes here') - # diff_frame = Apex::Frame.new('WI2ARD-1', 'OMG', ['WIDE2-2' 'WIDE1-1'], 'different payload') - # assert not orig_frame.eql? diff_frame - public - class UnpathedFrame - attr_accessor :source, :destination, :payload - - ## - # Creates a new frame, all fields are duplicated but and immutable. All - # fields are validated. - # - # @param source [Apex::Frame::Entity] The source callsign for the frame. Must be a - # non-null string of non-zero length with only letters, numbers and - # dashes. Will be converted uppercase. - # @param destination [Apex::Frame::Entity] The destination callsign for the frame. Must - # be a non-null string of non-zero length with only letters, numbers, - # and dashes. Will be converted to uppercase. - # @param payload [String] The payload of the frame. Must be a non-null - # string of non-zero length. - protected - def initialize(source, destination, payload) - raise ArgumentError.new("source argument can not be nil") if source.nil? - raise ArgumentError.new("destination argument can not be nil") if destination.nil? - raise ArgumentError.new("payload argument can not be nil") if payload.nil? + # @param source [Apex::Entity] The source callsign for the frame. Must be a + # non-null string of non-zero length with only letters, numbers and + # dashes. Will be converted uppercase. + # @param destination [Apex::Entity] The destination callsign for the frame. Must + # be a non-null string of non-zero length with only letters, numbers, + # and dashes. Will be converted to uppercase. + # @param payload [String] The payload of the frame. Must be a non-null + # string of non-zero length. + protected + def initialize(source, destination, payload) + raise ArgumentError.new("source argument can not be nil") if source.nil? + raise ArgumentError.new("destination argument can not be nil") if destination.nil? + raise ArgumentError.new("payload argument can not be nil") if payload.nil? - raise ArgumentError.new("source argument must be a Entity, but found: " + source.class.to_s) if not source.kind_of? Apex::Frame::Entity - raise ArgumentError.new("destination argument must be a Entity, but found: " + source.class.to_s) if not destination.kind_of? Apex::Frame::Entity - raise ArgumentError.new("payload argument must be a string, but found: " + source.class.to_s) if not payload.kind_of? String + raise ArgumentError.new("source argument must be a Entity, but found: " + source.class.to_s) if not source.kind_of? Apex::Entity + raise ArgumentError.new("destination argument must be a Entity, but found: " + source.class.to_s) if not destination.kind_of? Apex::Entity + raise ArgumentError.new("payload argument must be a string, but found: " + source.class.to_s) if not payload.kind_of? String - # The following both duplicate/clone the argument and convert it to uppercase - @source = source - @destination = destination - @payload = payload.dup.freeze - end + # The following both duplicate/clone the argument and convert it to uppercase + @source = source + @destination = destination + @payload = payload.dup.freeze + end - public - def path_agnostic_eql?(other) - raise ArgumentError.new("The argument must be either an UnpathedFrame or a PathAgnosticFrame") if not ((other.instance_of? Apex::Frame::UnpathedFrame) || (other.instance_of? Apex::Frame::PathAgnosticFrame)) + public + def path_agnostic_eql?(other) + raise ArgumentError.new("The argument must be either an UnpathedFrame or a PathAgnosticFrame") if not ((other.instance_of? Apex::UnpathedFrame) || (other.instance_of? Apex::PathAgnosticFrame)) - return self.path_agnostic_equality? other - end + return self.path_agnostic_equality? other + end - public - def path_agnostic_equality?(other) - return false if (not other.respond_to? :source) || - (not other.respond_to? :destination) || - (not other.respond_to? :payload) + public + def path_agnostic_equality?(other) + return false if (not other.respond_to? :source) || + (not other.respond_to? :destination) || + (not other.respond_to? :payload) - if (self.source.eql? other.source) && (self.destination.eql? other.destination) && (self.payload.eql? other.payload) - return true - else - return false - end + if (self.source.eql? other.source) && (self.destination.eql? other.destination) && (self.payload.eql? other.payload) + return true + else + return false end + end - public - def path_agnostic_hash - return [self.source, self.destination, self.payload].hash - end + public + def path_agnostic_hash + return [self.source, self.destination, self.payload].hash + end - public - def ==(other) - return self.path_agnostic_equality? other - end + public + def ==(other) + return self.path_agnostic_equality? other + end - public - def eql?(other) - self.path_agnostic_eql? other - end + public + def eql?(other) + self.path_agnostic_eql? other + end - public - def hash - return self.path_agnostic_hash - end + public + def hash + return self.path_agnostic_hash end end end diff --git a/spec/apex/encoder/aprs_kiss_spec.rb b/spec/apex/encoder/aprs_kiss_spec.rb index 5333f47c40e82db757b9a739a63f7b308f4e4bdf..54d9c5e9bb3f268eb6f9a03ef8e2d052f00669a2 100644 --- a/spec/apex/encoder/aprs_kiss_spec.rb +++ b/spec/apex/encoder/aprs_kiss_spec.rb @@ -1,10 +1,9 @@ -require_relative '../../../lib/apex/encoder/aprs_kiss' -require_relative '../../../lib/apex/frame' +require_relative '../../../lib/apex' -FRAME_KISS = Apex::Frame::Frame.new( - Apex::Frame::Entity.from_raw('W2GMD-1'), - Apex::Frame::Entity.from_raw('OMG'), - Apex::Frame::Path.from_raw(['WIDE1-1', 'WIDE2-2']), +FRAME_KISS = Apex::Frame.new( + Apex::Entity.from_raw('W2GMD-1'), + Apex::Entity.from_raw('OMG'), + Apex::Path.from_raw(['WIDE1-1', 'WIDE2-2']), 'test_encode_frame' ) diff --git a/spec/apex/encoder/igate_tcp_spec.rb b/spec/apex/encoder/igate_tcp_spec.rb index 5242dac68cb671c1d08aa98388c4fee7bb775a6b..f1b660771dc4e516b5e2e2aaf85089f58934c5d0 100644 --- a/spec/apex/encoder/igate_tcp_spec.rb +++ b/spec/apex/encoder/igate_tcp_spec.rb @@ -1,11 +1,9 @@ -require_relative '../../../lib/apex/encoder/igate_tcp' -require_relative '../../../lib/apex/frame' -require_relative '../../../lib/apex/app_info' +require_relative '../../../lib/apex' -DECODED_FRAME_IGATE = Apex::Frame::Frame.new( - Apex::Frame::Entity.from_raw('W2GMD-1'), - Apex::Frame::Entity.from_raw('OMG'), - Apex::Frame::Path.from_raw(['WIDE1-1', 'WIDE2-2']), +DECODED_FRAME_IGATE = Apex::Frame.new( + Apex::Entity.from_raw('W2GMD-1'), + Apex::Entity.from_raw('OMG'), + Apex::Path.from_raw(['WIDE1-1', 'WIDE2-2']), 'test_encode_frame' ) ENCODED_FRAME_IGATE = "W2GMD-1>OMG,WIDE1-1,WIDE2-2:test_encode_frame" diff --git a/spec/apex/frame/entity_spec.rb b/spec/apex/frame/entity_spec.rb index 48dae5e4dfcadfadc48aaaa837ab9001cac34e38..ef1022d900b252256c2b382e01cb6b6bb7432b51 100644 --- a/spec/apex/frame/entity_spec.rb +++ b/spec/apex/frame/entity_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../lib/apex/frame/entity' +require_relative '../../../lib/apex' BASE_ENTITY = "WI2ARD-10".freeze BASE_ENTITY_CALLSIGN = "WI2ARD".freeze @@ -39,13 +39,13 @@ class EntityEquiv end end -describe Apex::Frame::Entity do +describe Apex::Entity do describe ".new" do context "Given a valid callsign with ssid" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) it "returns a Entity object with correct properties" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "set the callsign property correctly" do expect(entity.callsign).to eql(BASE_ENTITY_CALLSIGN) @@ -58,10 +58,10 @@ describe Apex::Frame::Entity do end end context "Given a valid callsign with nil ssid" do - entity = Apex::Frame::Entity.new(NOSSID_ENTITY_CALLSIGN, NOSSID_ENTITY_SSID) + entity = Apex::Entity.new(NOSSID_ENTITY_CALLSIGN, NOSSID_ENTITY_SSID) it "returns a Entity object with correct properties" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "set the callsign property correctly" do expect(entity.callsign).to eql(NOSSID_ENTITY_CALLSIGN) @@ -71,10 +71,10 @@ describe Apex::Frame::Entity do end end context "Given a valid callsign with zero for ssid" do - entity = Apex::Frame::Entity.new(ZEROSSID_ENTITY_CALLSIGN, ZEROSSID_ENTITY_SSID) + entity = Apex::Entity.new(ZEROSSID_ENTITY_CALLSIGN, ZEROSSID_ENTITY_SSID) it "returns a Entity object with correct properties" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "set the callsign property correctly" do expect(entity.callsign).to eql(ZEROSSID_ENTITY_CALLSIGN) @@ -86,60 +86,60 @@ describe Apex::Frame::Entity do context "Given an invalid callsign with valid ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(BAD_CALLSIGN_ENTITY_CALLSIGN, BAD_CALLSIGN_ENTITY_SSID) + entity = Apex::Entity.new(BAD_CALLSIGN_ENTITY_CALLSIGN, BAD_CALLSIGN_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a nil callsign with valid ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(nil, BASE_ENTITY_SSID) + entity = Apex::Entity.new(nil, BASE_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a non-string callsign with valid ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(5, BASE_ENTITY_SSID) + entity = Apex::Entity.new(5, BASE_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a empty string callsign with valid ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new("", BASE_ENTITY_SSID) + entity = Apex::Entity.new("", BASE_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a valid callsign with non-integer ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, "invalid") + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, "invalid") }.to raise_error(ArgumentError) end end context "Given a valid callsign with ssid below 0" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(BAD_LOWSSID_ENTITY_CALLSIGN,BAD_LOWSSID_ENTITY_SSID) + entity = Apex::Entity.new(BAD_LOWSSID_ENTITY_CALLSIGN,BAD_LOWSSID_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a valid callsign with ssid above 15" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.new(BAD_HIGHSSID_ENTITY_CALLSIGN,BAD_HIGHSSID_ENTITY_SSID) + entity = Apex::Entity.new(BAD_HIGHSSID_ENTITY_CALLSIGN,BAD_HIGHSSID_ENTITY_SSID) }.to raise_error(ArgumentError) end end context "Given a lowercase callsign with valid ssid" do - entity = Apex::Frame::Entity.new("wi2ard", 2) + entity = Apex::Entity.new("wi2ard", 2) it "converts the callsign to uppercase" do expect(entity.callsign).to eql("WI2ARD") end end context "Given a callsign with extra spaces before and after and valid ssid" do - entity = Apex::Frame::Entity.new(" WI2ARD ", 2) + entity = Apex::Entity.new(" WI2ARD ", 2) it "strips the extra spaces" do expect(entity.callsign).to eql("WI2ARD") end @@ -147,10 +147,10 @@ describe Apex::Frame::Entity do end describe ".from_raw" do context "Given a valid callsign with ssid" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) it "returns a Entity object" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "set the callsign correctly" do expect(entity.callsign).to eql(BASE_ENTITY_CALLSIGN) @@ -160,10 +160,10 @@ describe Apex::Frame::Entity do end end context "Given a valid callsign with 0 ssid" do - entity = Apex::Frame::Entity.from_raw(ZEROSSID_ENTITY) + entity = Apex::Entity.from_raw(ZEROSSID_ENTITY) it "returns a FrameEntity object" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "the callsign field was parssed correctly" do expect(entity.callsign).to eql(ZEROSSID_ENTITY_CALLSIGN) @@ -173,10 +173,10 @@ describe Apex::Frame::Entity do end end context "Given a valid callsign with no ssid" do - entity = Apex::Frame::Entity.from_raw(NOSSID_ENTITY) + entity = Apex::Entity.from_raw(NOSSID_ENTITY) it "returns a FrameEntity object" do expect(entity).not_to be_nil - expect(entity).to be_kind_of(Apex::Frame::Entity) + expect(entity).to be_kind_of(Apex::Entity) end it "the callsign field was parssed correctly" do expect(entity.callsign).to eql(NOSSID_ENTITY_CALLSIGN) @@ -188,47 +188,47 @@ describe Apex::Frame::Entity do context "Given an invalid callsign with valid ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.from_raw(BAD_CALLSIGN_ENTITY) + entity = Apex::Entity.from_raw(BAD_CALLSIGN_ENTITY) }.to raise_error(ArgumentError) end end context "Given a entity with two hyphens" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.from_raw(BAD_HYPHEN_ENTITY) + entity = Apex::Entity.from_raw(BAD_HYPHEN_ENTITY) }.to raise_error(ArgumentError) end end context "Given a entity with a hyphen but no ssid" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.from_raw(BAD_HYPHEN_NOSSID_ENTITY) + entity = Apex::Entity.from_raw(BAD_HYPHEN_NOSSID_ENTITY) }.to raise_error(ArgumentError) end end context "Given a entity with a an ssid greater than 15" do it "throws an argument error" do expect { - entity = Apex::Frame::Entity.from_raw(BAD_HIGHSSID_ENTITY) + entity = Apex::Entity.from_raw(BAD_HIGHSSID_ENTITY) }.to raise_error(ArgumentError) end end end describe ".callsign" do context "Given a Entity with valid callsign and with an ssid" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) it "then the callsign should be frozen" do expect(entity.callsign).to be_frozen end end context "Given a Entity with valid callsign and without an ssid" do - entity = Apex::Frame::Entity.from_raw(NOSSID_ENTITY) + entity = Apex::Entity.from_raw(NOSSID_ENTITY) it "then the callsign should be frozen" do expect(entity.callsign).to be_frozen end end context "Given any valid Entity" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) it "then we should not be able to set a value" do expect { entity.callsign = "BAD1B" @@ -242,7 +242,7 @@ describe Apex::Frame::Entity do it "then the callsign passed to from_raw should be duplicated" do passed_call = "WI2AR" orig_call = passed_call.dup.freeze - entity = Apex::Frame::Entity.from_raw(passed_call) + entity = Apex::Entity.from_raw(passed_call) passed_call << "D" expect(entity.callsign).to eql(orig_call) expect(passed_call).to eql("WI2ARD") @@ -252,7 +252,7 @@ describe Apex::Frame::Entity do end describe ".ssid" do context "Given any valid Entity" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) it "then we should not be able to set a value" do expect { entity.ssid = "1" @@ -267,7 +267,7 @@ describe Apex::Frame::Entity do end describe ".decrement_ssid" do context "Given a Entity that has a greater than 0 ssid" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) context "which has its ssid decremented" do new_entity = entity.decrement_ssid it "should produce a duplicated Entity" do @@ -282,7 +282,7 @@ describe Apex::Frame::Entity do end end context "Given a Entity that has a ssid of 0" do - entity = Apex::Frame::Entity.from_raw(ZEROSSID_ENTITY) + entity = Apex::Entity.from_raw(ZEROSSID_ENTITY) context "which has its ssid decremented" do it "throws a range error" do expect{ @@ -294,31 +294,31 @@ describe Apex::Frame::Entity do end describe ".to_s" do context "Given a raw string with valid callsign with ssid" do - entity = Apex::Frame::Entity.from_raw(BASE_ENTITY) + entity = Apex::Entity.from_raw(BASE_ENTITY) it "then we should produce the correct string" do expect(entity.to_s).to eql(BASE_ENTITY) end end context "Given a raw string with valid callsign with ssid of zero" do - entity = Apex::Frame::Entity.from_raw(ZEROSSID_ENTITY) + entity = Apex::Entity.from_raw(ZEROSSID_ENTITY) it "then we should produce the correct string" do expect(entity.to_s).to eql(NOSSID_ENTITY) end end context "Given a raw string with valid callsign without ssid" do - entity = Apex::Frame::Entity.from_raw(NOSSID_ENTITY) + entity = Apex::Entity.from_raw(NOSSID_ENTITY) it "then we should produce the correct string" do expect(entity.to_s).to eql(NOSSID_ENTITY) end end context "Given a FrameEntity from new with valid callsign with non-zero ssid" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) it "then we should produce the correct string" do expect(entity.to_s).to eql(BASE_ENTITY) end end context "Given a FrameEntity from new with valid callsign with ssid of 0" do - entity = Apex::Frame::Entity.new(ZEROSSID_ENTITY_CALLSIGN, ZEROSSID_ENTITY_SSID) + entity = Apex::Entity.new(ZEROSSID_ENTITY_CALLSIGN, ZEROSSID_ENTITY_SSID) it "then we should produce the correct string" do expect(entity.to_s).to eql(NOSSID_ENTITY) end @@ -328,15 +328,15 @@ describe Apex::Frame::Entity do describe ".==" do context "Given one Entity and an equivelant non-Entity class with the same properties" do entity_equiv = EntityEquiv.new - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) it "then equality should return true" do expect(entity == entity_equiv).to be_truthy end end context "Given two equivelant entitys both instaces of Entity class with the same properties" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, 0) - entity_equiv = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, nil) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, 0) + entity_equiv = Apex::Entity.new(BASE_ENTITY_CALLSIGN, nil) it "then equality should return true" do expect(entity == entity_equiv).to be_truthy end @@ -344,15 +344,15 @@ describe Apex::Frame::Entity do context "Given one Entity and a equivelant non-Entity class with different properties" do entity_equiv = EntityEquiv.new - entity = Apex::Frame::Entity.new("BADCALL", BASE_ENTITY_SSID) + entity = Apex::Entity.new("BADCALL", BASE_ENTITY_SSID) it "then equality should return true" do expect(entity == entity_equiv).to be_falsey end end context "Given two equivelant entitys both instaces of Entity class with different properties" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, 0) - entity_equiv = Apex::Frame::Entity.new("BADCALL", nil) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, 0) + entity_equiv = Apex::Entity.new("BADCALL", nil) it "then equality should return true" do expect(entity == entity_equiv).to be_falsey end @@ -362,7 +362,7 @@ describe Apex::Frame::Entity do describe ".eql?" do context "Given one Entity and an equivelant non-Entity class with the same properties" do entity_equiv = EntityEquiv.new - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, BASE_ENTITY_SSID) it "throws an ArgumentError" do expect { entity.eql? entity_equiv @@ -371,8 +371,8 @@ describe Apex::Frame::Entity do end context "Given two equivelant entitys both instaces of Entity class" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, 0) - entity_equiv = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, nil) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, 0) + entity_equiv = Apex::Entity.new(BASE_ENTITY_CALLSIGN, nil) it "then eql should return true" do expect(entity.eql? entity_equiv).to be_truthy end @@ -380,7 +380,7 @@ describe Apex::Frame::Entity do context "Given one Entity and a equivelant non-Entity class with different properties" do entity_equiv = EntityEquiv.new - entity = Apex::Frame::Entity.new("BADCALL", BASE_ENTITY_SSID) + entity = Apex::Entity.new("BADCALL", BASE_ENTITY_SSID) it "throws an ArgumentError" do expect { entity.eql? entity_equiv @@ -389,8 +389,8 @@ describe Apex::Frame::Entity do end context "Given two equivelant entitys both instaces of Entity class with different properties" do - entity = Apex::Frame::Entity.new(BASE_ENTITY_CALLSIGN, 0) - entity_equiv = Apex::Frame::Entity.new("BADCALL", nil) + entity = Apex::Entity.new(BASE_ENTITY_CALLSIGN, 0) + entity_equiv = Apex::Entity.new("BADCALL", nil) it "then eql should return false" do expect(entity.eql? entity_equiv).to be_falsey end diff --git a/spec/apex/frame/hop_spec.rb b/spec/apex/frame/hop_spec.rb index 9eb2c660fc6a256668fe5c41e58c3e7b8257d972..b0416fc06543f0259f33dab403aeff427db23927 100644 --- a/spec/apex/frame/hop_spec.rb +++ b/spec/apex/frame/hop_spec.rb @@ -65,13 +65,13 @@ class HopEquiv end end -describe Apex::Frame::Hop do +describe Apex::Hop do describe ".new" do context "Given a valid callsign with ssid and with seen flag" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) it "returns a FrameHop object with correct properties" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "set the callsign property correctly" do expect(hop.callsign).to eql(BASE_HOP_CALLSIGN) @@ -84,10 +84,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign with nil ssid and with seen flag" do - hop = Apex::Frame::Hop.new(NOSSID_HOP_CALLSIGN, NOSSID_HOP_SSID, NOSSID_HOP_SEEN) + hop = Apex::Hop.new(NOSSID_HOP_CALLSIGN, NOSSID_HOP_SSID, NOSSID_HOP_SEEN) it "returns a FrameHop object with correct properties" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "set the callsign property correctly" do expect(hop.callsign).to eql(NOSSID_HOP_CALLSIGN) @@ -100,10 +100,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign with zero for ssid and with seen flag" do - hop = Apex::Frame::Hop.new(ZEROSSID_HOP_CALLSIGN, ZEROSSID_HOP_SSID, ZEROSSID_HOP_SEEN) + hop = Apex::Hop.new(ZEROSSID_HOP_CALLSIGN, ZEROSSID_HOP_SSID, ZEROSSID_HOP_SEEN) it "returns a FrameHop object with correct properties" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "set the callsign property correctly" do expect(hop.callsign).to eql(ZEROSSID_HOP_CALLSIGN) @@ -118,74 +118,74 @@ describe Apex::Frame::Hop do context "Given an invalid callsign with valid ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BAD_CALLSIGN_HOP_CALLSIGN, BAD_CALLSIGN_HOP_SSID, BAD_CALLSIGN_HOP_SEEN) + hop = Apex::Hop.new(BAD_CALLSIGN_HOP_CALLSIGN, BAD_CALLSIGN_HOP_SSID, BAD_CALLSIGN_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a nil callsign with valid ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(nil, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(nil, BASE_HOP_SSID, BASE_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a valid callsign with valid ssid and nil seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, nil) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, nil) }.to raise_error(ArgumentError) end end context "Given a non-string callsign with valid ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(5, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(5, BASE_HOP_SSID, BASE_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a empty string callsign with valid ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new("", BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new("", BASE_HOP_SSID, BASE_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a valid callsign with non-integer ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, "invalid", BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, "invalid", BASE_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a valid callsign with valid ssid and non-boolean seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN,BASE_HOP_SSID, "invalid") + hop = Apex::Hop.new(BASE_HOP_CALLSIGN,BASE_HOP_SSID, "invalid") }.to raise_error(ArgumentError) end end context "Given a valid callsign with ssid below 0 and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BAD_LOWSSID_HOP_CALLSIGN,BAD_LOWSSID_HOP_SSID, BAD_LOWSSID_HOP_SEEN) + hop = Apex::Hop.new(BAD_LOWSSID_HOP_CALLSIGN,BAD_LOWSSID_HOP_SSID, BAD_LOWSSID_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a valid callsign with ssid above 15 and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.new(BAD_HIGHSSID_HOP_CALLSIGN,BAD_HIGHSSID_HOP_SSID, BAD_HIGHSSID_HOP_SEEN) + hop = Apex::Hop.new(BAD_HIGHSSID_HOP_CALLSIGN,BAD_HIGHSSID_HOP_SSID, BAD_HIGHSSID_HOP_SEEN) }.to raise_error(ArgumentError) end end context "Given a lowercase callsign with valid ssid and valid seen flag" do - hop = Apex::Frame::Hop.new("wi2ard", 2, true) + hop = Apex::Hop.new("wi2ard", 2, true) it "converts the callsign to uppercase" do expect(hop.callsign).to eql("WI2ARD") end end context "Given a callsign with extra spaces before and after and valid ssid and valid seen flag" do - hop = Apex::Frame::Hop.new(" WI2ARD ", 2, true) + hop = Apex::Hop.new(" WI2ARD ", 2, true) it "strips the extra spaces" do expect(hop.callsign).to eql("WI2ARD") end @@ -193,10 +193,10 @@ describe Apex::Frame::Hop do end describe ".from_raw" do context "Given a valid callsign with ssid and with seen flag" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "returns a FrameHop object" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "set the callsign correctly" do expect(hop.callsign).to eql(BASE_HOP_CALLSIGN) @@ -209,10 +209,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign with ssid and without seen flag" do - hop = Apex::Frame::Hop.from_raw(UNSEEN_HOP) + hop = Apex::Hop.from_raw(UNSEEN_HOP) it "returns a FrameHop object" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "the callsign field was parssed correctly" do expect(hop.callsign).to eql(UNSEEN_HOP_CALLSIGN) @@ -225,10 +225,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign with 0 ssid and with seen flag" do - hop = Apex::Frame::Hop.from_raw(ZEROSSID_HOP) + hop = Apex::Hop.from_raw(ZEROSSID_HOP) it "returns a FrameHop object" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "the callsign field was parssed correctly" do expect(hop.callsign).to eql(ZEROSSID_HOP_CALLSIGN) @@ -241,10 +241,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign with nil ssid and with seen flag" do - hop = Apex::Frame::Hop.from_raw(NOSSID_HOP) + hop = Apex::Hop.from_raw(NOSSID_HOP) it "returns a FrameHop object" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "the callsign field was parssed correctly" do expect(hop.callsign).to eql(NOSSID_HOP_CALLSIGN) @@ -257,10 +257,10 @@ describe Apex::Frame::Hop do end end context "Given a valid callsign without ssid and without seen flag" do - hop = Apex::Frame::Hop.from_raw(NOSSID_UNSEEN_HOP) + hop = Apex::Hop.from_raw(NOSSID_UNSEEN_HOP) it "returns a FrameHop object" do expect(hop).not_to be_nil - expect(hop).to be_kind_of(Apex::Frame::Hop) + expect(hop).to be_kind_of(Apex::Hop) end it "the callsign field was parssed correctly" do expect(hop.callsign).to eql(NOSSID_UNSEEN_HOP_CALLSIGN) @@ -275,47 +275,47 @@ describe Apex::Frame::Hop do context "Given an invalid callsign with valid ssid and valid seen flag" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.from_raw(BAD_CALLSIGN_HOP) + hop = Apex::Hop.from_raw(BAD_CALLSIGN_HOP) }.to raise_error(ArgumentError) end end context "Given a hop with two hyphens" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.from_raw(BAD_HYPHEN_HOP) + hop = Apex::Hop.from_raw(BAD_HYPHEN_HOP) }.to raise_error(ArgumentError) end end context "Given a hop with a hyphen but no ssid" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.from_raw(BAD_HYPHEN_NOSSID_HOP) + hop = Apex::Hop.from_raw(BAD_HYPHEN_NOSSID_HOP) }.to raise_error(ArgumentError) end end context "Given a hop with a an ssid greater than 15" do it "throws an argument error" do expect { - hop = Apex::Frame::Hop.from_raw(BAD_HIGHSSID_HOP) + hop = Apex::Hop.from_raw(BAD_HIGHSSID_HOP) }.to raise_error(ArgumentError) end end end describe ".callsign" do context "Given a FrameHop with valid callsign and with an ssid" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "then the callsign should be frozen" do expect(hop.callsign).to be_frozen end end context "Given a FrameHop with valid callsign and without an ssid" do - hop = Apex::Frame::Hop.from_raw(NOSSID_HOP) + hop = Apex::Hop.from_raw(NOSSID_HOP) it "then the callsign should be frozen" do expect(hop.callsign).to be_frozen end end context "Given any valid FrameHop" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "then we should not be able to set a value" do expect { hop.callsign = "BAD1B" @@ -329,7 +329,7 @@ describe Apex::Frame::Hop do it "then the callsign passed to from_raw should be duplicated" do passed_call = "WI2AR" orig_call = passed_call.dup.freeze - hop = Apex::Frame::Hop.from_raw(passed_call) + hop = Apex::Hop.from_raw(passed_call) passed_call << "D" expect(hop.callsign).to eql(orig_call) expect(passed_call).to eql("WI2ARD") @@ -339,7 +339,7 @@ describe Apex::Frame::Hop do end describe ".ssid" do context "Given any valid FrameHop" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "then we should not be able to set a value" do expect { hop.ssid = "1" @@ -354,7 +354,7 @@ describe Apex::Frame::Hop do end describe ".seen" do context "Given any valid FrameHop" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "then we should not be able to set a value" do expect { hop.seen = false @@ -364,7 +364,7 @@ describe Apex::Frame::Hop do end describe ".toggle_seen" do context "Given a FrameHop that has been seen" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) context "which has its seen flag toggled" do toggled_hop = hop.toggle_seen it "should produce a duplicated FrameHop" do @@ -379,7 +379,7 @@ describe Apex::Frame::Hop do end end context "Given a FrameHop that has not been seen" do - hop = Apex::Frame::Hop.from_raw(UNSEEN_HOP) + hop = Apex::Hop.from_raw(UNSEEN_HOP) context "which has its seen flag toggled" do new_hop = hop.toggle_seen it "should produce a duplicated FrameHop" do @@ -396,7 +396,7 @@ describe Apex::Frame::Hop do end describe ".decrement_ssid" do context "Given a FrameHop that has a greater than 0 SSID" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) context "which has its ssid decremented" do new_hop = hop.decrement_ssid it "should produce a duplicated FrameHop" do @@ -411,7 +411,7 @@ describe Apex::Frame::Hop do end end context "Given a FrameHop that has a SSID of 0" do - hop = Apex::Frame::Hop.from_raw(ZEROSSID_HOP) + hop = Apex::Hop.from_raw(ZEROSSID_HOP) context "which has its ssid decremented" do it "throws a range error" do expect{ @@ -423,67 +423,67 @@ describe Apex::Frame::Hop do end describe ".to_s" do context "Given a raw string with valid callsign with ssid and with seen flag" do - hop = Apex::Frame::Hop.from_raw(BASE_HOP) + hop = Apex::Hop.from_raw(BASE_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(BASE_HOP) end end context "Given a raw string with valid callsign with non-zero ssid and without seen flag" do - hop = Apex::Frame::Hop.from_raw(UNSEEN_HOP) + hop = Apex::Hop.from_raw(UNSEEN_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(UNSEEN_HOP) end end context "Given a raw string with valid callsign with ssid of zero and without seen flag" do - hop = Apex::Frame::Hop.from_raw(ZEROSSID_HOP) + hop = Apex::Hop.from_raw(ZEROSSID_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_HOP) end end context "Given a raw string with valid callsign without ssid and with seen flag" do - hop = Apex::Frame::Hop.from_raw(NOSSID_HOP) + hop = Apex::Hop.from_raw(NOSSID_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_HOP) end end context "Given a raw string with valid callsign without ssid and without seen flag" do - hop = Apex::Frame::Hop.from_raw(NOSSID_UNSEEN_HOP) + hop = Apex::Hop.from_raw(NOSSID_UNSEEN_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_UNSEEN_HOP) end end context "Given a raw string with valid callsign with ssid of 0 and without seen flag" do - hop = Apex::Frame::Hop.from_raw(ZEROSSID_UNSEEN_HOP) + hop = Apex::Hop.from_raw(ZEROSSID_UNSEEN_HOP) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_UNSEEN_HOP) end end context "Given a FrameHop from new with valid callsign with non-zero ssid and with seen flag" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) it "then we should produce the correct string" do expect(hop.to_s).to eql(BASE_HOP) end end context "Given a FrameHop from new with valid callsign with non-zero ssid and without seen flag" do - hop = Apex::Frame::Hop.new(UNSEEN_HOP_CALLSIGN, UNSEEN_HOP_SSID, UNSEEN_HOP_SEEN) + hop = Apex::Hop.new(UNSEEN_HOP_CALLSIGN, UNSEEN_HOP_SSID, UNSEEN_HOP_SEEN) it "then we should produce the correct string" do expect(hop.to_s).to eql(UNSEEN_HOP) end end context "Given a FrameHop from new with valid callsign with nil ssid and with seen flag" do - hop = Apex::Frame::Hop.new(NOSSID_HOP_CALLSIGN, NOSSID_HOP_SSID, NOSSID_HOP_SEEN) + hop = Apex::Hop.new(NOSSID_HOP_CALLSIGN, NOSSID_HOP_SSID, NOSSID_HOP_SEEN) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_HOP) end end context "Given a FrameHop from new with valid callsign with ssid of 0 and with seen flag" do - hop = Apex::Frame::Hop.new(ZEROSSID_HOP_CALLSIGN, ZEROSSID_HOP_SSID, ZEROSSID_HOP_SEEN) + hop = Apex::Hop.new(ZEROSSID_HOP_CALLSIGN, ZEROSSID_HOP_SSID, ZEROSSID_HOP_SEEN) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_HOP) end end context "Given a FrameHop from new with valid callsign with ssid of zero and without seen flag" do - hop = Apex::Frame::Hop.new(ZEROSSID_UNSEEN_HOP_CALLSIGN, ZEROSSID_UNSEEN_HOP_SSID, ZEROSSID_UNSEEN_HOP_SEEN) + hop = Apex::Hop.new(ZEROSSID_UNSEEN_HOP_CALLSIGN, ZEROSSID_UNSEEN_HOP_SSID, ZEROSSID_UNSEEN_HOP_SEEN) it "then we should produce the correct string" do expect(hop.to_s).to eql(NOSSID_UNSEEN_HOP) end @@ -493,15 +493,15 @@ describe Apex::Frame::Hop do describe ".==" do context "Given one Hop and an equivelant non-Hop class with the same properties" do hop_equiv = HopEquiv.new - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) it "then equality should return true" do expect(hop == hop_equiv).to be_truthy end end context "Given two equivelant hops both instaces of Hop class with the same properties" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) - hop_equiv = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, nil, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) + hop_equiv = Apex::Hop.new(BASE_HOP_CALLSIGN, nil, BASE_HOP_SEEN) it "then equality should return true" do expect(hop == hop_equiv).to be_truthy end @@ -509,15 +509,15 @@ describe Apex::Frame::Hop do context "Given one Hop and a equivelant non-Hop class with different properties" do hop_equiv = HopEquiv.new - hop = Apex::Frame::Hop.new("BADCALL", BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new("BADCALL", BASE_HOP_SSID, BASE_HOP_SEEN) it "then equality should return true" do expect(hop == hop_equiv).to be_falsey end end context "Given two equivelant hops both instaces of Hop class with different properties" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) - hop_equiv = Apex::Frame::Hop.new("BADCALL", nil, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) + hop_equiv = Apex::Hop.new("BADCALL", nil, BASE_HOP_SEEN) it "then equality should return true" do expect(hop == hop_equiv).to be_falsey end @@ -527,7 +527,7 @@ describe Apex::Frame::Hop do describe ".eql?" do context "Given one Hop and an equivelant non-Hop class with the same properties" do hop_equiv = HopEquiv.new - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, BASE_HOP_SSID, BASE_HOP_SEEN) it "throws an ArgumentError" do expect { hop.eql? hop_equiv @@ -536,8 +536,8 @@ describe Apex::Frame::Hop do end context "Given two equivelant hops both instaces of Hop class" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) - hop_equiv = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, nil, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) + hop_equiv = Apex::Hop.new(BASE_HOP_CALLSIGN, nil, BASE_HOP_SEEN) it "then eql should return true" do expect(hop.eql? hop_equiv).to be_truthy end @@ -545,7 +545,7 @@ describe Apex::Frame::Hop do context "Given one Hop and a equivelant non-Hop class with different properties" do hop_equiv = HopEquiv.new - hop = Apex::Frame::Hop.new("BADCALL", BASE_HOP_SSID, BASE_HOP_SEEN) + hop = Apex::Hop.new("BADCALL", BASE_HOP_SSID, BASE_HOP_SEEN) it "throws an ArgumentError" do expect { hop.eql? hop_equiv @@ -554,8 +554,8 @@ describe Apex::Frame::Hop do end context "Given two equivelant hops both instaces of Hop class with different properties" do - hop = Apex::Frame::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) - hop_equiv = Apex::Frame::Hop.new("BADCALL", nil, BASE_HOP_SEEN) + hop = Apex::Hop.new(BASE_HOP_CALLSIGN, 0, BASE_HOP_SEEN) + hop_equiv = Apex::Hop.new("BADCALL", nil, BASE_HOP_SEEN) it "then eql should return false" do expect(hop.eql? hop_equiv).to be_falsey end diff --git a/spec/apex/frame/path_spec.rb b/spec/apex/frame/path_spec.rb index d0c2149db66d7fcc82ab977eb7ad4534d9f16a50..9b77fa45440548302b9072778d0355fbdce8538e 100644 --- a/spec/apex/frame/path_spec.rb +++ b/spec/apex/frame/path_spec.rb @@ -1,34 +1,34 @@ require_relative '../../../lib/apex/frame/path' -describe Apex::Frame::Path do +describe Apex::Path do describe ".new" do context "Given no arguments" do it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.new() + path = Apex::Path.new() }.to raise_error(ArgumentError) end end context "Given a single nil argument" do it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.new(nil) + path = Apex::Path.new(nil) }.to raise_error(ArgumentError) end end context "Given a single non-Hop argument" do it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.new(5) + path = Apex::Path.new(5) }.to raise_error(ArgumentError) end end context "Given a single valid hop" do - hop = Apex::Frame::Hop.new("WI2ARD", 4, true) - path = Apex::Frame::Path.new(hop) + hop = Apex::Hop.new("WI2ARD", 4, true) + path = Apex::Path.new(hop) it "instantiates a Path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "with a single hop" do expect(path.length).to eql(1) @@ -41,17 +41,17 @@ describe Apex::Frame::Path do end it "the Path can not be appended" do expect { - path << Apex::Frame::Hop.from_raw("NO4CALL-6") + path << Apex::Hop.from_raw("NO4CALL-6") }.to raise_error(NoMethodError) end end context "Given two valid hops" do - hop1 = Apex::Frame::Hop.new("WI2ARD", 4, true) - hop2 = Apex::Frame::Hop.new("K3TXD", 0, false) - path = Apex::Frame::Path.new(hop1, hop2) + hop1 = Apex::Hop.new("WI2ARD", 4, true) + hop2 = Apex::Hop.new("K3TXD", 0, false) + path = Apex::Path.new(hop1, hop2) it "instantiates a Path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "with two hops" do expect(path.length).to eql(2) @@ -63,11 +63,11 @@ describe Apex::Frame::Path do end context "Given two hops where the first is unseen and second is seen" do - hop1 = Apex::Frame::Hop.new("WI2ARD", 4, false) - hop2 = Apex::Frame::Hop.new("K3TXD", 0, true) + hop1 = Apex::Hop.new("WI2ARD", 4, false) + hop2 = Apex::Hop.new("K3TXD", 0, true) it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.new(hop1, hop2) + path = Apex::Path.new(hop1, hop2) }.to raise_error(ArgumentError) end end @@ -75,10 +75,10 @@ describe Apex::Frame::Path do describe ".from_raw" do context "Given an array of two valid hops as strings" do - path = Apex::Frame::Path.from_raw(['WIDE2-2', "WI2ARD"]) + path = Apex::Path.from_raw(['WIDE2-2', "WI2ARD"]) it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(2) @@ -89,10 +89,10 @@ describe Apex::Frame::Path do end end context "Given an array of a single valid hop as a string" do - path = Apex::Frame::Path.from_raw(['WIDE2-2']) + path = Apex::Path.from_raw(['WIDE2-2']) it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(1) @@ -102,10 +102,10 @@ describe Apex::Frame::Path do end end context "Given a single string of two valid hops" do - path = Apex::Frame::Path.from_raw("WIDE2-2,WI2ARD") + path = Apex::Path.from_raw("WIDE2-2,WI2ARD") it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(2) @@ -116,10 +116,10 @@ describe Apex::Frame::Path do end end context "Given a single string for a single valid hop" do - path = Apex::Frame::Path.from_raw("WIDE2-2") + path = Apex::Path.from_raw("WIDE2-2") it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(1) @@ -129,10 +129,10 @@ describe Apex::Frame::Path do end end context "Given an array of two hops as strings with space as padding" do - path = Apex::Frame::Path.from_raw([' WIDE2-2 ', " WI2ARD"]) + path = Apex::Path.from_raw([' WIDE2-2 ', " WI2ARD"]) it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(2) @@ -143,10 +143,10 @@ describe Apex::Frame::Path do end end context "Given a single string of two valid hops with space as padding" do - path = Apex::Frame::Path.from_raw(" WIDE2-2 , WI2ARD") + path = Apex::Path.from_raw(" WIDE2-2 , WI2ARD") it "instantiates a path" do expect(path).to_not be_nil - expect(path).to be_kind_of(Apex::Frame::Path) + expect(path).to be_kind_of(Apex::Path) end it "has exactly two hops" do expect(path.length).to eql(2) @@ -159,14 +159,14 @@ describe Apex::Frame::Path do context "Given an array of two hops as strings with invalid commas appended" do it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.from_raw(['WIDE2-2,', "WI2ARD"]) + path = Apex::Path.from_raw(['WIDE2-2,', "WI2ARD"]) }.to raise_error(ArgumentError) end end context "Given an array of a single element but with two hops as a single string" do it "throws an ArgumentError" do expect { - path = Apex::Frame::Path.from_raw(["WIDE2-2,WI2ARD"]) + path = Apex::Path.from_raw(["WIDE2-2,WI2ARD"]) }.to raise_error(ArgumentError) end end @@ -174,7 +174,7 @@ describe Apex::Frame::Path do describe ".each" do context "Given a valid path with two hops" do - path = Apex::Frame::Path.from_raw(["WIDE2-2", "WI2ARD"]) + path = Apex::Path.from_raw(["WIDE2-2", "WI2ARD"]) it "can be iterated over twice but no more" do hop_count = 0 path.each do |hop| @@ -187,19 +187,19 @@ describe Apex::Frame::Path do describe ".[]" do context "Given a valid path with two hops" do - path = Apex::Frame::Path.from_raw(["WIDE2-2", "WI2ARD"]) + path = Apex::Path.from_raw(["WIDE2-2", "WI2ARD"]) it "the first hop can be referenced via array notation" do - expect(path[0]).to eql(Apex::Frame::Hop.from_raw("WIDE2-2")) + expect(path[0]).to eql(Apex::Hop.from_raw("WIDE2-2")) end it "the second hop can be referenced via array notation" do - expect(path[1]).to eql(Apex::Frame::Hop.from_raw("WI2ARD")) + expect(path[1]).to eql(Apex::Hop.from_raw("WI2ARD")) end end end describe ".length" do context "Given a valid path with two hops" do - path = Apex::Frame::Path.from_raw(["WIDE2-2", "WI2ARD"]) + path = Apex::Path.from_raw(["WIDE2-2", "WI2ARD"]) it "the length should be exactly 2" do expect(path.length).to eql(2) end @@ -208,7 +208,7 @@ describe Apex::Frame::Path do describe ".to_s" do context "Given a valid path with two hops" do - path = Apex::Frame::Path.from_raw(["WIDE2-2", "WI2ARD"]) + path = Apex::Path.from_raw(["WIDE2-2", "WI2ARD"]) it "the string should represent the path" do expect(path.to_s).to eql("WIDE2-2,WI2ARD") end @@ -217,7 +217,7 @@ describe Apex::Frame::Path do describe ".to_string_array" do context "Given a valid path with two hops" do - let(:path) {Apex::Frame::Path.from_raw("WIDE2-2,WI2ARD")} + let(:path) {Apex::Path.from_raw("WIDE2-2,WI2ARD")} it "do" do expect(path.to_string_array).to eql(["WIDE2-2", "WI2ARD"]) end