data_science_theater_3000 0.0.7.1 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,10 +6,14 @@ require "data_science_theater_3000/version"
|
|
6
6
|
module DataScienceTheater3000
|
7
7
|
# Converts an ip address into a location hash
|
8
8
|
#
|
9
|
-
# @param [String] ip
|
10
|
-
# @return [Hash] hash of location information.
|
9
|
+
# @param [Array, String] ip Either an array of ip strings or a single ip address to be located
|
10
|
+
# @return [Hash] hash of location information. Singular output can be passed as input to coordinates2politics
|
11
11
|
def self.ip2coordinates ip
|
12
12
|
url = "http://www.datasciencetoolkit.org"
|
13
|
+
if ip.class == Array
|
14
|
+
ip.each {|i| i.gsub!(",", "%2c") }
|
15
|
+
ip = ActiveSupport::JSON.encode(ip)
|
16
|
+
end
|
13
17
|
response = Curl::Easy.perform( url + "/ip2coordinates/" + ip ).body_str
|
14
18
|
|
15
19
|
coordinates = make_hashy(response)
|
@@ -23,42 +27,49 @@ module DataScienceTheater3000
|
|
23
27
|
# Converts a street address into a location hash
|
24
28
|
#
|
25
29
|
# @param [String, Array] address as either a single string or array of strings
|
26
|
-
# @return [Hash] hash of location information.
|
30
|
+
# @return [Hash] hash of location information. Singular output can be passed as input to coordinates2politics
|
27
31
|
def self.street2coordinates address
|
28
32
|
url = "http://www.datasciencetoolkit.org"
|
29
33
|
if address.class == String
|
30
34
|
address.gsub!(",", "%2c").gsub!(" ", "+")
|
31
|
-
response = Curl::Easy.perform( url + "/street2coordinates/" + address ).body_str
|
32
35
|
elsif address.class == Array
|
33
36
|
address.each {|a| a.gsub!(",", "%2c").gsub!(" ", "+") }
|
34
37
|
address = ActiveSupport::JSON.encode(address)
|
35
|
-
response = Curl::Easy.perform( url + "/street2coordinates/" + address ).body_str
|
36
38
|
end
|
39
|
+
response = Curl::Easy.perform( url + "/street2coordinates/" + address ).body_str
|
40
|
+
|
37
41
|
coordinates = make_hashy(response)
|
38
42
|
end
|
39
43
|
|
40
44
|
# Uses latitude,longitude pair to find detailed political information about a location.
|
41
45
|
# Currently supporting a single pair.
|
42
46
|
#
|
43
|
-
# @param [Hash,String] hash returned from ip2coordinates/street2coordinates or just a string like "33,-86"
|
47
|
+
# @param [Hash,String] coords hash returned from ip2coordinates/street2coordinates or just a string like "33,-86"
|
44
48
|
# @return [Array] contains hashes with detailed political information for a location
|
45
49
|
def self.coordinates2politics coords
|
46
|
-
if coords.class == Hash
|
47
|
-
coords = coords.keys.map{|k| "#{coords[k]["latitude"]},#{coords[k]["longitude"]}"}.first
|
48
|
-
end
|
49
|
-
|
50
50
|
url = "http://www.datasciencetoolkit.org"
|
51
|
+
if coords.class == Hash && coords.keys.count == 1
|
52
|
+
coords = coords.keys.map{ |k| "#{coords[k]["latitude"]},#{coords[k]["longitude"]}" }.first
|
53
|
+
end
|
51
54
|
coords.gsub!( "," , "%2c" )
|
52
55
|
response = Curl::Easy.perform( url + "/coordinates2politics/" + coords ).body_str
|
53
56
|
|
54
|
-
|
57
|
+
politics = make_hashy(response)
|
55
58
|
end
|
56
59
|
|
60
|
+
# Specify a name or names and return parsed result as well as a best-guess for gender
|
61
|
+
#
|
62
|
+
# @param [Array, String] name can be array of name strings or a single name
|
63
|
+
# @return [Hash] information related to the provided name
|
57
64
|
def self.text2people name
|
58
|
-
|
59
|
-
|
65
|
+
url = "http://www.datasciencetoolkit.org"
|
66
|
+
name = ActiveSupport::JSON.encode(name)
|
67
|
+
c = Curl::Easy.new( url + '/text2people')
|
68
|
+
c.multipart_form_post = true
|
69
|
+
c.http_post(Curl::PostField.content('body', name))
|
70
|
+
response = c.body_str
|
60
71
|
|
61
|
-
|
72
|
+
person = make_hashy(response)
|
62
73
|
end
|
63
74
|
|
64
75
|
def self.text2times text
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_science_theater_3000
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-22 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_support
|
16
|
-
requirement: &
|
16
|
+
requirement: &14674740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14674740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: curb
|
27
|
-
requirement: &
|
27
|
+
requirement: &14674140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14674140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &14673300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14673300
|
47
47
|
description: Ruby interface to issue Data Science Toolkit API calls.
|
48
48
|
email:
|
49
49
|
- tad@isotope11.com
|