crunchbase 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -5
- data/VERSION +1 -1
- data/crunchbase.gemspec +2 -2
- data/lib/crunchbase.rb +2 -2
- data/lib/crunchbase/search.rb +42 -9
- data/spec/crunchbase/search_spec.rb +42 -0
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -40,6 +40,9 @@ an array.
|
|
40
40
|
first_result = s[0]
|
41
41
|
s.each { |result| puts result.name }
|
42
42
|
|
43
|
+
The Search will return a list consisting of objects of the SearchResult type. To
|
44
|
+
access the full entity object, call the +entity+ method of the SearchResult.
|
45
|
+
|
43
46
|
While Search does include the Enumerable module, it does not implement all of
|
44
47
|
the methods of Array. If you need to treat the results as an array in a way not
|
45
48
|
supported, you can call +to_ary+; this prefetches all result pages (if they have
|
@@ -47,7 +50,6 @@ not already been loaded), so it may entail a slight delay, depending on the
|
|
47
50
|
number of results.
|
48
51
|
|
49
52
|
all_results = s.to_ary
|
50
|
-
result_slice = s[3..6]
|
51
53
|
|
52
54
|
=== List all Items
|
53
55
|
|
@@ -59,9 +61,10 @@ type, you can do so with the +all+ method.
|
|
59
61
|
|
60
62
|
This returns an array containing objects representing each entity. Just like
|
61
63
|
Search, the full item can be grabbed with the +entity+ method. Unlike Search,
|
62
|
-
however, all of the
|
63
|
-
not entail a delay every ten items. Of course, the list is
|
64
|
-
|
64
|
+
however, all of the result objects are fetched at once, so iterating through the
|
65
|
+
list does not entail a delay every ten items. Of course, the list is enormous
|
66
|
+
(the list of all companies returns over 84,500 entries as of this writing), so
|
67
|
+
it's little consolation.
|
65
68
|
|
66
69
|
== Copyright
|
67
70
|
|
@@ -69,4 +72,4 @@ Copyright (c) 2011-12 Tyler Cunnion. This software is made available under the
|
|
69
72
|
MIT/X11 license. See LICENSE.txt for further details.
|
70
73
|
|
71
74
|
I am not affiliated in any way with AOL, TechCrunch, Crunchbase, or anyone
|
72
|
-
really.
|
75
|
+
really.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/crunchbase.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{crunchbase}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Tyler Cunnion}]
|
12
|
-
s.date = %q{2012-
|
12
|
+
s.date = %q{2012-03-16}
|
13
13
|
s.email = %q{tyler.cunnion@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
data/lib/crunchbase.rb
CHANGED
data/lib/crunchbase/search.rb
CHANGED
@@ -32,15 +32,20 @@ module Crunchbase
|
|
32
32
|
populate_results(json)
|
33
33
|
end
|
34
34
|
|
35
|
-
def [](
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
def [](*args)
|
36
|
+
case args.length
|
37
|
+
when 1
|
38
|
+
key = args[0]
|
39
|
+
if key.kind_of?(Integer)
|
40
|
+
get_single_key(key)
|
41
|
+
elsif key.kind_of?(Range)
|
42
|
+
get_range(key)
|
43
43
|
end
|
44
|
+
when 2
|
45
|
+
start = args[0]
|
46
|
+
length = args[1]
|
47
|
+
start = @size + start if start < 0
|
48
|
+
get_range(start..start+length-1)
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -59,6 +64,7 @@ module Crunchbase
|
|
59
64
|
|
60
65
|
private
|
61
66
|
|
67
|
+
# Inserts items into the results array from the retrieved search page
|
62
68
|
def populate_results(json)
|
63
69
|
page = json["page"]
|
64
70
|
results = json["results"].map{|r| SearchResult.new(r)}
|
@@ -66,9 +72,36 @@ module Crunchbase
|
|
66
72
|
@results[start, results.length] = results
|
67
73
|
end
|
68
74
|
|
75
|
+
# Retrieves the search page containing the given index
|
69
76
|
def retrieve_for_index(index)
|
70
77
|
page = (index / 10) + 1
|
71
78
|
populate_results(API.search(@query, page))
|
72
79
|
end
|
80
|
+
|
81
|
+
# Given one integer key, returns the indexed object from results
|
82
|
+
def get_single_key(key)
|
83
|
+
key = @size+key if key < 0
|
84
|
+
r = @results[key]
|
85
|
+
unless r.nil? && key < @size
|
86
|
+
r
|
87
|
+
else
|
88
|
+
retrieve_for_index(key)
|
89
|
+
@results[key]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Given a range, returns the array slice of results indicated
|
94
|
+
def get_range(range)
|
95
|
+
r = []
|
96
|
+
enum = range.to_enum
|
97
|
+
begin
|
98
|
+
while (x = enum.next) < @size
|
99
|
+
r << get_single_key(x)
|
100
|
+
end
|
101
|
+
rescue StopIteration
|
102
|
+
end
|
103
|
+
r.empty? ? nil : r
|
104
|
+
end
|
105
|
+
|
73
106
|
end
|
74
|
-
end
|
107
|
+
end
|
@@ -9,6 +9,48 @@ module Crunchbase
|
|
9
9
|
s[0].class.should == SearchResult
|
10
10
|
end
|
11
11
|
|
12
|
+
describe "advanced indexing" do
|
13
|
+
before(:all) do
|
14
|
+
@s = Search.find('google')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return slices with ranges" do
|
18
|
+
slice = @s[8..11]
|
19
|
+
slice.class.should == Array
|
20
|
+
slice[0].class.should == SearchResult
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return abbreviated slice for range with upper out of range" do
|
24
|
+
slice = @s[@s.size-3..@s.size+2]
|
25
|
+
slice.length.should == 3
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return nil for slice out of range" do
|
29
|
+
slice = @s[@s.size..@s.size+4]
|
30
|
+
slice.should == nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should slice with two arguments" do
|
34
|
+
start = @s.size / 3
|
35
|
+
slice = @s[start, 5]
|
36
|
+
slice.length.should == 5
|
37
|
+
slice[0].class.should == SearchResult
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should slice with negative start" do
|
41
|
+
slice = @s[-12, 4]
|
42
|
+
slice.length.should == 4
|
43
|
+
slice[0].class.should == SearchResult
|
44
|
+
end
|
45
|
+
|
46
|
+
end #Indexing
|
47
|
+
|
48
|
+
it "should accept negative indices" do
|
49
|
+
s = Search.find('google')
|
50
|
+
s[-13].should == s[s.size-13]
|
51
|
+
s[-13].class.should == SearchResult
|
52
|
+
end
|
53
|
+
|
12
54
|
it "should return higher search results" do
|
13
55
|
s = Search.find('google')
|
14
56
|
s[s.size/2].class.should == SearchResult
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crunchbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70161600273460 !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: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70161600273460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70161600233040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70161600233040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70161600230540 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70161600230540
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70161600229340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70161600229340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &70161600227720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70161600227720
|
69
69
|
description:
|
70
70
|
email: tyler.cunnion@gmail.com
|
71
71
|
executables: []
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: 4593283541442877220
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|