lib/packetgen/header/ospfv3/lsa.rb in packetgen-2.6.0 vs lib/packetgen/header/ospfv3/lsa.rb in packetgen-2.7.0
- old
+ new
@@ -6,11 +6,10 @@
# frozen_string_literal: true
module PacketGen
module Header
class OSPFv3
-
# This class handles links in a {LSARouter OSPFv3 LSA router payload}.
# @author Sylvain Daubert
class Link < Types::Fields
# @!attribute type
# @return [Integer]
@@ -51,11 +50,11 @@
class LSA < LSAHeader
# @!attribute body
# LSA body
# @return [String]
define_field :body, Types::String,
- builder: ->(h,t) { t.new(length_from: ->() { h.length - 20 }) }
+ builder: ->(h, t) { t.new(length_from: -> { h.length - 20 }) }
end
# This class handles OSPFv3 LSA Router payloads.
#
# A LSA router payload is composed of:
@@ -183,11 +182,11 @@
# of {LSA LSAs} or {LSAHeader LSAHeaders}. It recognizes known LSA types
# and infers correct type.
# @author Sylvain Daubert
class ArrayOfLSA < Types::Array
set_of LSA
-
+
# @param [Hash] options
# @option options [Types::Int] counter Int object used as a counter for this set
# @option options [Boolean] only_headers if +true+, only {LSAHeader LSAHeaders}
# will be added to this array.
def initialize(options={})
@@ -199,32 +198,32 @@
# @param [String] str
# @return [self]
def read(str)
clear
return self if str.nil?
- return self if @counter and @counter.to_i == 0
+ return self if @counter && @counter.to_i.zero?
force_binary str
- while str.length > 0
+ until str.empty?
lsa = LSAHeader.new.read(str)
- if !@only_headers
+ unless @only_headers
klass = get_lsa_class_by_human_type(lsa.human_type)
lsa = klass.new.read(str[0...lsa.length])
end
self.push lsa
str.slice!(0, lsa.sz)
- break if @counter and self.size == @counter.to_i
+ break if @counter && (self.size == @counter.to_i)
end
self
end
private
def record_from_hash(hsh)
- unless hsh.has_key? :type
- raise ArgumentError, "hash should have :type key"
+ unless hsh.key? :type
+ raise ArgumentError, 'hash should have :type key'
end
-
+
klass = if @only_headers
LSAHeader
else
case hsh[:type]
when String
@@ -237,10 +236,10 @@
end
klass.new(hsh)
end
def get_lsa_class_by_human_type(htype)
- klassname = "LSA#{htype.to_s.gsub(/-/, '')}"
+ klassname = "LSA#{htype.to_s.delete('-')}"
if OSPFv3.const_defined? klassname
OSPFv3.const_get klassname
else
LSA
end