Class: Ax25::ImmutablePath
- Inherits:
-
Object
- Object
- Ax25::ImmutablePath
- Includes:
- Path
- Defined in:
- lib/ax25/frame/immutable_path.rb
Constant Summary collapse
- EMPTY_PATH =
ImmutablePath.new().freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](idx) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #length ⇒ Object
- #seen_hops ⇒ Object
- #to_array ⇒ Object
- #to_s ⇒ Object
- #to_string_array ⇒ Object
- #unseen_hops ⇒ Object
Class Method Details
.from_raw(raw_path, strict_callsign: true, strict_ssid: true) ⇒ Object
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 51 52 |
# File 'lib/ax25/frame/immutable_path.rb', line 26 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 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? :[] new_path_array = [] raw_path.each do |hop| if hop.kind_of? Ax25::Hop new_hop = hop else new_hop = Ax25::ImmutableHop.from_raw(hop, strict_callsign: strict_callsign, strict_ssid: strict_ssid) end new_path_array << new_hop end return Ax25::ImmutablePath.new(*new_path_array) end |
Instance Method Details
#==(other) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ax25/frame/immutable_path.rb', line 84 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 (0..self.length - 1).each do |idx| return false if not self[idx].eql? other[idx] end return true end |
#[](idx) ⇒ Object
62 63 64 |
# File 'lib/ax25/frame/immutable_path.rb', line 62 def [](idx) return @path_array[idx].dup.freeze end |
#each ⇒ Object
55 56 57 58 59 |
# File 'lib/ax25/frame/immutable_path.rb', line 55 def each @path_array.each do |hop| yield(hop) end end |
#empty? ⇒ Boolean
72 73 74 |
# File 'lib/ax25/frame/immutable_path.rb', line 72 def empty? return @path_array.empty? end |
#eql?(other) ⇒ Boolean
77 78 79 80 81 |
# File 'lib/ax25/frame/immutable_path.rb', line 77 def eql?(other) raise ArgumentError.new("The argument must be of type Path (or a child class).") if not other.kind_of? Path return self == other end |
#length ⇒ Object
67 68 69 |
# File 'lib/ax25/frame/immutable_path.rb', line 67 def length return @path_array.length end |
#seen_hops ⇒ Object
117 118 119 |
# File 'lib/ax25/frame/immutable_path.rb', line 117 def seen_hops @path_array.select { |hop| hop.seen } end |
#to_array ⇒ Object
107 108 109 |
# File 'lib/ax25/frame/immutable_path.rb', line 107 def to_array return @path_array.dup end |
#to_s ⇒ Object
97 98 99 |
# File 'lib/ax25/frame/immutable_path.rb', line 97 def to_s return @path_array.join(',') end |
#to_string_array ⇒ Object
102 103 104 |
# File 'lib/ax25/frame/immutable_path.rb', line 102 def to_string_array return @path_array.map {|e| e.to_s} end |
#unseen_hops ⇒ Object
112 113 114 |
# File 'lib/ax25/frame/immutable_path.rb', line 112 def unseen_hops @path_array.select { |hop| !hop.seen } end |