Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitbourahlavignal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Arrêt du service - 11/07 de 07h30 à 07h45 - Mise à jour de sécurité
Show more breadcrumbs
VIGNAL Nicolas
gitbourahlavignal
Commits
6bf73cfc
Commit
6bf73cfc
authored
10 years ago
by
Mike Mackintosh
Browse files
Options
Downloads
Patches
Plain Diff
added #to range and fixed #40
parent
09bde2a5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/ipaddress/ipv4.rb
+21
-1
21 additions, 1 deletion
lib/ipaddress/ipv4.rb
test/ipaddress/ipv4_test.rb
+13
-0
13 additions, 0 deletions
test/ipaddress/ipv4_test.rb
with
34 additions
and
1 deletion
lib/ipaddress/ipv4.rb
+
21
−
1
View file @
6bf73cfc
...
@@ -640,6 +640,26 @@ module IPAddress;
...
@@ -640,6 +640,26 @@ module IPAddress;
end
end
alias_method
:arpa
,
:
reverse
alias_method
:arpa
,
:
reverse
#
# Return a list of IP's between @address
# and the supplied IP
#
# ip = IPAddress("172.16.100.51/32")
#
# ip.to("172.16.100.100")
# #=> ["172.16.100.51",
# "172.16.100.52",
# ...
# "172.16.100.99",
# "172.16.100.100"]
#
def
to
(
e
)
unless
e
.
is_a?
IPAddress
::
IPv4
e
=
IPv4
.
new
(
e
)
end
Range
.
new
(
@u32
,
e
.
to_u32
).
map
{
|
i
|
IPAddress
.
ntoa
(
i
)
}
end
#
#
# Splits a network into different subnets
# Splits a network into different subnets
#
#
...
@@ -1028,7 +1048,7 @@ module IPAddress;
...
@@ -1028,7 +1048,7 @@ module IPAddress;
# Tweaked to remove the #upto(32)
# Tweaked to remove the #upto(32)
def
newprefix
(
num
)
def
newprefix
(
num
)
return
@prefix
+
(
Math
::
log2
(
num
).
to_i
)
return
@prefix
+
(
Math
::
log2
(
num
).
ceil
)
end
end
def
sum_first_found
(
arr
)
def
sum_first_found
(
arr
)
...
...
This diff is collapsed.
Click to expand it.
test/ipaddress/ipv4_test.rb
+
13
−
0
View file @
6bf73cfc
...
@@ -64,6 +64,11 @@ class IPv4Test < Minitest::Test
...
@@ -64,6 +64,11 @@ class IPv4Test < Minitest::Test
"10.1.1.1"
=>
8
,
"10.1.1.1"
=>
8
,
"150.1.1.1"
=>
16
,
"150.1.1.1"
=>
16
,
"200.1.1.1"
=>
24
}
"200.1.1.1"
=>
24
}
@in_range
=
{
"10.32.0.1"
=>
[
"10.32.0.253"
,
253
],
"192.0.0.0"
=>
[
"192.1.255.255"
,
131072
]
}
end
end
...
@@ -551,6 +556,14 @@ class IPv4Test < Minitest::Test
...
@@ -551,6 +556,14 @@ class IPv4Test < Minitest::Test
assert_equal
x
.
split
(
256
).
length
,
256
assert_equal
x
.
split
(
256
).
length
,
256
end
end
end
end
def
test_in_range
@in_range
.
each
do
|
s
,
d
|
ip
=
@klass
.
new
(
s
)
assert_equal
ip
.
to
(
d
[
0
]).
length
,
d
[
1
]
end
end
end
# class IPv4Test
end
# class IPv4Test
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment