mtodd-geoip 0.5.2 → 0.5.3

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.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/geoip.c +15 -0
  3. data/test.rb +20 -0
  4. metadata +1 -1
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'geoip'
25
- s.version = "0.5.2"
25
+ s.version = "0.5.3"
26
26
 
27
27
  s.authors = ['Ryah Dahl', 'Matt Todd', 'Charles Brian Quinn']
28
28
  s.email = 'mtodd@highgroove.com'
data/geoip.c CHANGED
@@ -168,6 +168,19 @@ VALUE rb_geoip_org_look_up(VALUE self, VALUE addr) {
168
168
 
169
169
  /* GeoIP *********************************************************************/
170
170
 
171
+ /* Returns the numeric form of an IP address.
172
+ *
173
+ * For example:
174
+ * 24.24.24.24 => 404232216
175
+ *
176
+ * This is used in order to be able to perform searches in CSV versions of the
177
+ * data files or in SQL records if the data has been put there.
178
+ */
179
+ VALUE rb_geoip_addr_to_num(VALUE self, VALUE addr) {
180
+ Check_Type(addr, T_STRING);
181
+ return INT2NUM(_GeoIP_addr_to_num(STR2CSTR(addr)));
182
+ }
183
+
171
184
  void Init_geoip()
172
185
  {
173
186
  mGeoIP = rb_define_module("GeoIP");
@@ -183,4 +196,6 @@ void Init_geoip()
183
196
  mGeoIP_Organization = rb_define_class_under(mGeoIP, "Organization", rb_cObject);
184
197
  rb_define_singleton_method( mGeoIP_Organization, "new", rb_geoip_org_new, -1);
185
198
  rb_define_method( mGeoIP_Organization, "look_up", rb_geoip_org_look_up, 1);
199
+
200
+ rb_define_singleton_method(mGeoIP, "addr_to_num", rb_geoip_addr_to_num, 1);
186
201
  }
data/test.rb CHANGED
@@ -14,6 +14,26 @@ class Test::Unit::TestCase
14
14
 
15
15
  end
16
16
 
17
+ class GeoIPTest < Test::Unit::TestCase
18
+
19
+ def test_addr_to_num_converts_an_ip_to_an_ipnum
20
+ ip = "24.24.24.24"
21
+ ipnum = 16777216*24 + 65536*24 + 256*24 + 24
22
+ assert_equal ipnum, GeoIP.addr_to_num(ip)
23
+ end
24
+
25
+ def test_addr_to_num_expects_an_ip_string
26
+ assert_raises TypeError do
27
+ GeoIP.addr_to_num(nil)
28
+ end
29
+ end
30
+
31
+ def test_addr_to_num_returns_zero_for_an_illformed_ip_string
32
+ assert_equal 0, GeoIP.addr_to_num("foo.bar")
33
+ end
34
+
35
+ end
36
+
17
37
  class GeoIPCityTest < Test::Unit::TestCase
18
38
 
19
39
  def setup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtodd-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Dahl