simple_geoip 0.0.2 → 0.0.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.
data/lib/simple_geoip.rb CHANGED
@@ -7,6 +7,7 @@ module SimpleGeoIP
7
7
 
8
8
  # parse this the web page and find lat and long, FUCK YEAH!
9
9
  def self.find_geo(ip_address)
10
+ return ["", ""] unless valid_ip? ip_address
10
11
  url = lookup_url ip_address
11
12
  doc = Nokogiri::HTML open(url)
12
13
  table = doc.search('table').last
@@ -23,5 +24,9 @@ module SimpleGeoIP
23
24
  def self.lookup_url(ip_address)
24
25
  API + ip_address
25
26
  end
27
+
28
+ def self.valid_ip?(ip_address)
29
+ !!ip_address.match(/^(\d{1,3}\.){3}\d{1,3}$/)
30
+ end
26
31
 
27
32
  end
data/simple_geoip.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  ## If your rubyforge_project name is different, then edit it and comment out
9
9
  ## the sub! line in the Rakefile
10
10
  s.name = 'simple_geoip'
11
- s.version = '0.0.2'
11
+ s.version = '0.0.3'
12
12
  s.date = '2011-05-30'
13
13
 
14
14
  ## Make sure your summary is short. The description may be as long
data/test/test_basics.rb CHANGED
@@ -15,5 +15,13 @@ class TestSimpleGeoIP < Test::Unit::TestCase
15
15
  lat, long = SimpleGeoIP::find_geo @test_ip
16
16
  assert_equal @geo_from_test_ip, [lat, long]
17
17
  end
18
+
19
+ def test_valid_ip_address
20
+ assert SimpleGeoIP::valid_ip?(@test_ip)
21
+ end
22
+
23
+ def test_invalid_ip_address
24
+ assert !SimpleGeoIP::valid_ip?("127.0.1/1")
25
+ end
18
26
 
19
27
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_geoip
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Ledet