ipconverter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -5
- data/bench.rb +5 -6
- data/ext/ipconverter/extconf.rb +0 -1
- data/ext/ipconverter/ipconverter.c +14 -2
- data/ipconverter.gemspec +13 -12
- data/lib/ipconverter.rb +7 -2
- data/lib/ipconverter/version.rb +1 -1
- data/test/test_ipconverter.rb +9 -9
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf2a5bcd16c2e1debc4e76243f377950e2e29886
|
4
|
+
data.tar.gz: e23960bd3f703c5a0e61eed15256ae7ac069cf79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b2fb9ad042f6c2dbca75ef28eae042d2df7a4a34371637e94b6e71ceae060157a8a0c3706d44fcbced43db9bb2ca3efcda03d95716fdcee693b49371dc3f11
|
7
|
+
data.tar.gz: 58f602f002d910d26c07563a82c4d10a95b06cc2be2fc05f0fac13a1c23cfb4030f499321652ec8d2a09489c8465e0859cb1f6495b9070f7a1ebaae05d7df216
|
data/Rakefile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
-
require
|
3
|
+
require 'rake/extensiontask'
|
4
4
|
|
5
5
|
Rake::TestTask.new do |t|
|
6
6
|
t.libs << 'test'
|
7
7
|
t.pattern = 'test/test_*.rb'
|
8
8
|
end
|
9
9
|
|
10
|
-
Rake::ExtensionTask.new
|
11
|
-
|
10
|
+
Rake::ExtensionTask.new 'ipconverter' do |ext|
|
11
|
+
ext.lib_dir = 'lib/ipconverter'
|
12
12
|
end
|
13
|
-
|
data/bench.rb
CHANGED
@@ -10,8 +10,8 @@ def ip_to_i2(ip)
|
|
10
10
|
octets = ip.split('.').map(&:to_i)
|
11
11
|
octets[3] +
|
12
12
|
octets[2] * 256 +
|
13
|
-
octets[1] * 256*256 +
|
14
|
-
octets[0] * 256*256*256
|
13
|
+
octets[1] * 256 * 256 +
|
14
|
+
octets[0] * 256 * 256 * 256
|
15
15
|
end
|
16
16
|
|
17
17
|
def ipaddr_to_i(ip)
|
@@ -29,13 +29,12 @@ ips = []
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
puts
|
32
|
+
puts 'iterations: ' + ips.length
|
33
33
|
|
34
34
|
Benchmark.bmbm do |x|
|
35
35
|
x.report('IPAddr#to_i') { ips.each { |ip| IPAddr.new(ip).to_i } }
|
36
36
|
x.report('pack/unpack') { ips.each { |ip| ip_to_i(ip) } }
|
37
37
|
x.report('split/multiply') { ips.each { |ip| ip_to_i2(ip) } }
|
38
|
-
x.report('C split/multiply') { ips.each {|ip| IpConverter.str_to_int(ip) } }
|
39
|
-
x.report('noop') { ips.each {|ip| ip } }
|
38
|
+
x.report('C split/multiply') { ips.each { |ip| IpConverter.str_to_int(ip) } }
|
39
|
+
x.report('noop') { ips.each { |ip| ip } }
|
40
40
|
end
|
41
|
-
|
data/ext/ipconverter/extconf.rb
CHANGED
@@ -9,8 +9,20 @@ void Init_ipconverter() {
|
|
9
9
|
rb_define_method(IpConverter, "str_to_int", method_str_to_int, 1);
|
10
10
|
}
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
/*
|
13
|
+
* call-seq:
|
14
|
+
* IpConverter.str_to_int(ip_addr_string) -> Fixnum
|
15
|
+
*
|
16
|
+
* Converts the passed IP address String into a Fixnum.
|
17
|
+
*
|
18
|
+
* Raises ArgumentError if ip address is not valid. Leading and trailing
|
19
|
+
* whitespace is ignored.
|
20
|
+
*
|
21
|
+
* Example:
|
22
|
+
* IpConverter.str_to_int("192.168.2.1")
|
23
|
+
* => 3232236033
|
24
|
+
*
|
25
|
+
*/
|
14
26
|
VALUE method_str_to_int(VALUE _module_, VALUE ip_string) {
|
15
27
|
|
16
28
|
// C string version of the ip_string
|
data/ipconverter.gemspec
CHANGED
@@ -6,23 +6,24 @@ $LOAD_PATH.unshift(ext) unless $LOAD_PATH.include?(ext)
|
|
6
6
|
require 'ipconverter/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
9
|
+
spec.name = 'ipconverter'
|
10
10
|
spec.version = IpConverter::VERSION
|
11
|
-
spec.authors = [
|
12
|
-
spec.email = [
|
13
|
-
spec.summary =
|
14
|
-
spec.description = %q
|
15
|
-
|
16
|
-
spec.
|
11
|
+
spec.authors = ['Joshua Scott']
|
12
|
+
spec.email = ['joshua.scott@gmail.com']
|
13
|
+
spec.summary = 'Utilities for working with IP addresses'
|
14
|
+
spec.description = %q(Fast C extension for converting IP addresses from
|
15
|
+
string to integer)
|
16
|
+
spec.homepage = 'http://github.com/joshuawscott/ipconverter'
|
17
|
+
spec.license = 'MIT'
|
17
18
|
|
18
19
|
spec.files = `git ls-files -z`.split("\x0")
|
19
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
21
|
spec.extensions = ['ext/ipconverter/extconf.rb']
|
21
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
-
spec.require_paths =
|
23
|
+
spec.require_paths = %w(lib ext)
|
23
24
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency 'rake-compiler',
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5'
|
28
|
+
spec.add_development_dependency 'rake-compiler', '~> 0.9'
|
28
29
|
end
|
data/lib/ipconverter.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'ipconverter/version'
|
2
|
+
require 'ipconverter/ipconverter'
|
3
3
|
|
4
|
+
# Contains the methods for doing IP Address conversions
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# IpConverter.str_to_int('192.168.2.1') # 3232236033
|
8
|
+
#
|
4
9
|
module IpConverter
|
5
10
|
module_function :str_to_int
|
6
11
|
end
|
data/lib/ipconverter/version.rb
CHANGED
data/test/test_ipconverter.rb
CHANGED
@@ -6,34 +6,34 @@ class TestIpConverter < MiniTest::Test
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_smallest_ip
|
9
|
-
int = IpConverter.str_to_int
|
9
|
+
int = IpConverter.str_to_int '0.0.0.0'
|
10
10
|
assert_equal int, 0
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_largest_ip
|
14
|
-
int = IpConverter.str_to_int
|
14
|
+
int = IpConverter.str_to_int '255.255.255.255'
|
15
15
|
# maximum 32-bit integer
|
16
16
|
assert_equal int, 256 * 256 * 256 * 256 - 1
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_handles_spaces
|
20
|
-
int = IpConverter.str_to_int
|
21
|
-
assert_equal int, IpConverter.str_to_int(
|
20
|
+
int = IpConverter.str_to_int ' 35.49.102.66 '
|
21
|
+
assert_equal int, IpConverter.str_to_int('35.49.102.66')
|
22
22
|
end
|
23
|
+
|
23
24
|
def test_no_overflow
|
24
|
-
assert_raises(ArgumentError) { IpConverter.str_to_int
|
25
|
+
assert_raises(ArgumentError) { IpConverter.str_to_int '12.12.0.256' }
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_short_ip
|
28
|
-
assert_raises(ArgumentError) { IpConverter.str_to_int
|
29
|
+
assert_raises(ArgumentError) { IpConverter.str_to_int '12.34.56' }
|
29
30
|
end
|
30
31
|
|
31
32
|
def test_long_ip
|
32
|
-
assert_raises(ArgumentError) { IpConverter.str_to_int
|
33
|
+
assert_raises(ArgumentError) { IpConverter.str_to_int '12.34.56.78.90' }
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_junk
|
36
|
-
assert_raises(ArgumentError) { IpConverter.str_to_int
|
37
|
+
assert_raises(ArgumentError) { IpConverter.str_to_int 'junk' }
|
37
38
|
end
|
38
|
-
|
39
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipconverter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Scott
|
@@ -66,7 +66,9 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
-
description:
|
69
|
+
description: |-
|
70
|
+
Fast C extension for converting IP addresses from
|
71
|
+
string to integer
|
70
72
|
email:
|
71
73
|
- joshua.scott@gmail.com
|
72
74
|
executables: []
|