freebase-importers 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,10 @@ require "#{File.dirname(__FILE__)}/freebase_importers/version"
6
6
  # https://developers.google.com/freebase/v1/mql-overview
7
7
  module FreebaseImporters
8
8
 
9
+ def self.debug!
10
+ ENV['FREEBASE_IMPORTS_DEBUG'] = 'true'
11
+ end
12
+
9
13
  Dir.glob("#{File.dirname(__FILE__)}/freebase_importers/*").each do |filename|
10
14
  class_name = File.basename(filename, '.*').split('_').collect(&:capitalize).join.to_sym
11
15
  autoload class_name, filename
@@ -37,7 +37,7 @@ module FreebaseImporters
37
37
  q.each do |result|
38
38
  yield new(result)
39
39
  end
40
- puts "Getting some more in #{pause} seconds."
40
+ puts "Getting some more in #{pause} seconds." unless pause == 0
41
41
  sleep pause
42
42
  q = q.next
43
43
  end
@@ -75,4 +75,4 @@ module FreebaseImporters
75
75
  "https://api.freebase.com/api/trans/raw#{path}"
76
76
  end
77
77
  end
78
- end
78
+ end
@@ -0,0 +1,20 @@
1
+ module FreebaseImporters
2
+ class President < Base
3
+ map :name
4
+ map :id
5
+
6
+ add_to_mql :"/government/us_president/presidency_number", []
7
+ add_method :presidency_numbers, -> { data["/government/us_president/presidency_number"] }
8
+
9
+ map :"/people/person/date_of_birth"
10
+ add_method :date_of_birth, -> {
11
+ date = data["/people/person/date_of_birth"]
12
+ date ? Date.parse(date) : nil rescue date
13
+ }
14
+
15
+ map :"/people/person/height_meters"
16
+
17
+ add_to_mql :type, "/government/us_president"
18
+ images!
19
+ end
20
+ end
@@ -38,7 +38,7 @@ module FreebaseImporters
38
38
  end
39
39
 
40
40
  def query
41
- # puts "About to mql: #{mql.inspect}"
41
+ puts "About to mql: #{mql.inspect}" if ENV['FREEBASE_IMPORTS_DEBUG']
42
42
  url = base_url
43
43
  url.query_values = {
44
44
  'query' => [mql].to_json,
@@ -1,3 +1,3 @@
1
1
  module FreebaseImporters
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,6 +14,15 @@ describe FreebaseImporters do
14
14
  end
15
15
  end
16
16
 
17
+ describe FreebaseImporters::President do
18
+ let (:president) { FreebaseImporters::President.first }
19
+ it "should have attributes" do
20
+ [:name, :id, :height_meters].each do |attr|
21
+ expect(president.send(attr)).not_to be_nil
22
+ end
23
+ end
24
+ end
25
+
17
26
  describe FreebaseImporters::Car do
18
27
  let(:car) { FreebaseImporters::Car.first }
19
28
  it "should have images and thumbnails" do
@@ -25,7 +34,7 @@ describe FreebaseImporters do
25
34
  it "should return a second page of results" do
26
35
  counter = 0
27
36
  images = []
28
- FreebaseImporters::Car.endless do |car|
37
+ FreebaseImporters::Car.endless(0) do |car|
29
38
  counter += 1
30
39
  images << car.image_url if counter < 50
31
40
  if counter > 120
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freebase-importers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-21 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -144,6 +144,7 @@ files:
144
144
  - lib/freebase_importers/car.rb
145
145
  - lib/freebase_importers/common_accessors.rb
146
146
  - lib/freebase_importers/person.rb
147
+ - lib/freebase_importers/president.rb
147
148
  - lib/freebase_importers/query.rb
148
149
  - lib/freebase_importers/query_builder.rb
149
150
  - lib/freebase_importers/version.rb
@@ -164,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
165
  version: '0'
165
166
  segments:
166
167
  - 0
167
- hash: 3609189692260758964
168
+ hash: -2158776484765248370
168
169
  required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  none: false
170
171
  requirements:
@@ -173,10 +174,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  version: '0'
174
175
  segments:
175
176
  - 0
176
- hash: 3609189692260758964
177
+ hash: -2158776484765248370
177
178
  requirements: []
178
179
  rubyforge_project:
179
- rubygems_version: 1.8.23
180
+ rubygems_version: 1.8.25
180
181
  signing_key:
181
182
  specification_version: 3
182
183
  summary: Import Freebase data.