lib/net/dns/rr/hinfo.rb in net-dns-0.9.0 vs lib/net/dns/rr/hinfo.rb in net-dns-0.20.0

- old
+ new

@@ -38,29 +38,27 @@ end private def subclass_new_from_hash(options) - if options.key?(:cpu) && options.key?(:os) - @cpu = options[:cpu] - @os = options[:os] - else - raise ArgumentError, ":cpu and :os fields are mandatory" - end + raise ArgumentError, ":cpu and :os fields are mandatory" unless options.key?(:cpu) && options.key?(:os) + + @cpu = options[:cpu] + @os = options[:os] end def subclass_new_from_string(str) @cpu, @os = check_hinfo(str) end def subclass_new_from_binary(data, offset) - len = data.unpack("@#{offset} C").first + len = data.unpack1("@#{offset} C") offset += 1 @cpu = data[offset..(offset + len)] offset += len - len = data.unpack("@#{offset} C").first + len = data.unpack1("@#{offset} C") offset += 1 @os = data[offset..(offset + len)] offset += len end @@ -71,14 +69,12 @@ def get_inspect value end def check_hinfo(input) - if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/ - [Regexp.last_match(1), Regexp.last_match(2)] - else - raise ArgumentError, "Invalid HINFO Section `#{input}'" - end + raise ArgumentError, "Invalid HINFO Section `#{input}'" unless input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/ + + [Regexp.last_match(1), Regexp.last_match(2)] end def build_pack @hinfo_pack = "" @hinfo_pack += [cpu.size].pack("C") + cpu