china_ad_ip_rb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f285d3eb6d3c0e13bad5b79e0d7966cd52ace0ce
4
- data.tar.gz: 14b3b1f0c3f956724a9a7882fa26a52fc9d09297
3
+ metadata.gz: 15c38105face1a412b29cb12fb04b2fae0a70666
4
+ data.tar.gz: d205d95bdf7e1ead4ac1badd9ecfedea5a6a10b1
5
5
  SHA512:
6
- metadata.gz: ca36394e6a9afa36dbf7d8c6af088cfbc013c8d560366fc032fda6188223accee050a962619c2f6c0235f8cd70c8cfdaf254505554dbf183542a21420a1d76ff
7
- data.tar.gz: ef6d1184776988464a336e0e055bf039dd89fd75eb81cc61626989152f389601ef85914b92a87b853af78ce76ebd699d37e2f86da3cac909e627e3bcb2029d76
6
+ metadata.gz: 2a7eeabe4c1969d670e0d9cab811b6d49dc708e6687683209bb3951cb51645067c6842461084a58d918f16ae4febddc8082242871121f328919906e081ad83d9
7
+ data.tar.gz: 2000ca89ac605c8777050d7d6ce37310c0ae08803c63a48546c711ddc04859366abfa30c63f659046279d454861e830583bf27196fee57d698f9a33016cab8c0
@@ -0,0 +1,54 @@
1
+ module ChinaAdIpRb
2
+
3
+ class IPv4
4
+
5
+ include ChinaAdIpRb
6
+
7
+ REGEXP = Regexp.new(/((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)/)
8
+
9
+
10
+ def initialize(str)
11
+ ip, netmask = str.split("/")
12
+
13
+ # Check the ip and remove white space
14
+ if ChinaAdIpRb.valid_ipv4?(ip)
15
+ @address = ip.strip
16
+ else
17
+ raise ArgumentError, "Invalid IP #{ip.inspect}"
18
+ end
19
+
20
+ # Array formed with the IP octets
21
+ @octets = @address.split(".").map{|i| i.to_i}
22
+ # 32 bits interger containing the address
23
+ @u32 = (@octets[0]<< 24) + (@octets[1]<< 16) + (@octets[2]<< 8) + (@octets[3])
24
+
25
+ end # def initialize
26
+
27
+
28
+ def address
29
+ @address
30
+ end
31
+
32
+ def octets
33
+ @octets
34
+ end
35
+
36
+ def to_s
37
+ @address
38
+ end
39
+
40
+ def u32
41
+ @u32
42
+ end
43
+ alias_method :to_i, :u32
44
+ alias_method :to_u32, :u32
45
+
46
+
47
+ def self.extract(str)
48
+ self.new REGEXP.match(str).to_s
49
+ end
50
+
51
+
52
+ end
53
+
54
+ end
@@ -1,3 +1,3 @@
1
1
  module ChinaAdIpRb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "china_ad_ip_rb/version"
2
- require 'china_ad_ip_rb/ipv4'
3
- require 'csv'
2
+ require "china_ad_ip_rb/ipv4"
3
+ require "csv"
4
4
 
5
5
  module ChinaAdIpRb
6
6
  NAME = "ChinaAdIpRb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: china_ad_ip_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - suezhen
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - china_ad_ip_rb.gemspec
54
54
  - lib/china_ad_ip_rb.rb
55
+ - lib/china_ad_ip_rb/ipv4.rb
55
56
  - lib/china_ad_ip_rb/version.rb
56
57
  homepage: https://github.com/suzhen/china_ad_ip_rb
57
58
  licenses: