whatismyip 1.0.0 → 1.0.1

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/VERSION +1 -1
  2. data/lib/whatismyip.rb +22 -9
  3. data/whatismyip.gemspec +2 -2
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -3,34 +3,47 @@ require 'nokogiri'
3
3
 
4
4
  class Whatismyip
5
5
 
6
+ attr_reader :public_ip
7
+
6
8
  def self.check
7
9
  %{
8
10
  Public IP:
9
11
  ==========
10
- #{check_public}
12
+ #{public_ip}
11
13
 
12
14
  Local IP's:
13
15
  ===========
14
- #{check_local}
16
+ #{display_locals}
15
17
  }.map {|l| (l.strip.empty?) ? l : l.lstrip }
16
18
  end
17
19
 
18
- def self.check_public
19
- doc = Nokogiri::HTML(open('http://whatismyip.com/automation/n09230945.asp', 'User-Agent' => "Ruby/#{RUBY_VERSION}"))
20
- doc.css('p').inner_html
20
+ def self.public_ip
21
+ return @public_ip unless @public_ip.nil?
22
+
23
+ begin
24
+ doc = Nokogiri::HTML(open('http://whatismyip.com/automation/n09230945.asp', 'User-Agent' => "Ruby/#{RUBY_VERSION}"))
25
+ @public_ip = doc.css('p').inner_html
26
+ rescue SocketError => e
27
+ puts "Unable to connect to remote server. Are you sure you're connected to the internet? If not, connect and try again."
28
+ nil
29
+ end
21
30
  end
22
31
 
23
- def self.check_local
32
+ def self.local_ips
24
33
  result = `ifconfig`
25
34
 
26
35
  sections = result.split(/^(?=[^\t])/)
27
36
  sections_with_relevant_ip = sections.select{ |i| i =~ /inet/ }
28
37
 
29
- sections_with_relevant_ip.map { |section|
38
+ Hash[sections_with_relevant_ip.collect { |section|
30
39
  device = section[/[^:]+/]
31
40
  ip = section[/inet ([^ ]+)/, 1]
32
- "#{device}: #{ip}\n"
33
- }.compact
41
+ [device.to_sym, ip]
42
+ }]
43
+ end
44
+
45
+ def self.display_locals
46
+ local_ips.map { |device, ip| "#{device}: #{ip}\n" }
34
47
  end
35
48
 
36
49
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{whatismyip}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jimmy Baker"]
12
- s.date = %q{2010-01-11}
12
+ s.date = %q{2010-01-15}
13
13
  s.default_executable = %q{whatismyip}
14
14
  s.description = %q{Lets you check your public and local ip addresses by simply typing 'whatismyip' on the command-line}
15
15
  s.email = %q{jimmybaker@me.com}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatismyip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Baker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-11 00:00:00 -06:00
12
+ date: 2010-01-15 00:00:00 -06:00
13
13
  default_executable: whatismyip
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency