Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dspinhirne/netaddr-rb
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinhirne committed Dec 19, 2018
2 parents 4eca61f + 14a0544 commit 38a4a64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/mask128.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def Mask128.parse(mask)
if (mask.start_with?("/")) # cidr format
mask = mask[1..-1] # remove "/"
end
return Mask128.new(mask.to_i)
return Mask128.new(Integer(mask))
rescue ArgumentError
raise ValidationError, "#{mask} is not valid integer."
end

#cmp compares equality with another Mask128. Return:
Expand Down
12 changes: 9 additions & 3 deletions lib/mask32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ def initialize(prefix_len)
def Mask32.parse(mask)
mask.strip!
if (mask.start_with?("/")) # cidr format
return Mask32.new(mask[1..-1].to_i) # remove "/"
elsif (!mask.include?("."))
return Mask32.new(mask.to_i)
mask = mask[1..-1] # remove "/"
end

if (!mask.include?("."))
begin
return Mask32.new(Integer(mask))
rescue ArgumentError
raise ValidationError, "#{mask} is not valid integer."
end
end

# for extended netmask
Expand Down

0 comments on commit 38a4a64

Please sign in to comment.