bbc_data_service 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ module BBCDataService
4
4
  include ActiveModel::Conversion
5
5
  extend ActiveModel::Naming
6
6
 
7
- attr_accessor :attributes
7
+ attr_accessor :attributes, :rdf_object
8
8
 
9
9
  def initialize(attributes = {})
10
10
  @attributes = attributes
@@ -17,7 +17,7 @@ module BBCDataService
17
17
  end
18
18
 
19
19
  def add_relationship(name, values)
20
- FeedFixture.instance_eval <<-EOS
20
+ FeedFixture.class_eval <<-EOS
21
21
  attr_accessor :#{name}
22
22
  EOS
23
23
  send("#{name}=", values)
@@ -27,7 +27,8 @@ module BBCDataService
27
27
  end
28
28
  fixtures.each do |fixture|
29
29
  current_fixture = BBCDataService::FeedFixture.new(self.instance_eval(self.execute_query(graph, query, mappings)))
30
- self.process_relationships(graph, registered_fixture, current_fixture, fixture)
30
+ current_fixture.rdf_object = fixture
31
+ current_fixture = self.process_relationships(graph, registered_fixture, current_fixture, fixture)
31
32
  results << current_fixture
32
33
  end
33
34
  results
@@ -40,22 +41,28 @@ module BBCDataService
40
41
  key = relationship.first
41
42
  values = relationship.last
42
43
  # Parse this set of RDF, then add to an array on the main object
43
- query = RDF::Query.new({
44
- :fixture => self.generate_query(values[:mappings], values[:rdf_type])
45
- })
46
- if values[:filter]
47
- solutions = query.execute(graph)
48
- fixtures = self.filter_graph(solutions, values[:filter])
44
+ if values[:foreign_key]
45
+ foreign_key = self.instance_eval("current_fixture.#{values[:foreign_key]}")
46
+ query = RDF::Query.new({
47
+ RDF::URI(foreign_key) => self.generate_query(values[:mappings], values[:rdf_type])
48
+ })
49
+ fixtures = query.execute(graph)
49
50
  else
51
+ query = RDF::Query.new({
52
+ :fixture => self.generate_query(values[:mappings], values[:rdf_type])
53
+ })
50
54
  fixtures = query.execute(graph)
51
55
  end
52
56
  results = []
53
57
  fixtures.each do |fixture|
54
- results << BBCDataService::FeedFixture.new(self.instance_eval(self.execute_query(graph, query, values[:mappings])))
58
+ current_fixture = BBCDataService::FeedFixture.new(self.instance_eval(self.execute_query(graph, query, values[:mappings])))
59
+ current_fixture.rdf_object = fixture
60
+ results << current_fixture
55
61
  end
56
62
  current_fixture.add_relationship(key, results)
57
63
  end
58
64
  end
65
+ current_fixture
59
66
  end
60
67
 
61
68
  def self.filter_graph(solutions, filter)
@@ -1,3 +1,3 @@
1
1
  module BBCDataService
2
- VERSION = "1.4"
2
+ VERSION = "1.5"
3
3
  end
@@ -71,4 +71,9 @@ describe BBCDataService::FixtureLoader do
71
71
  object.name.should == "Germany"
72
72
  end
73
73
 
74
+ it "should allow finding of other resources" do
75
+ object = BBCDataService::FixtureLoader.load_fixture(:relationship_with_foreign_key)
76
+ object.first.team.first.name.should == "Team GB"
77
+ end
78
+
74
79
  end
@@ -0,0 +1 @@
1
+ {"http:\/\/www.bbc.co.uk\/things\/7ef7ffdf-f101-4470-adc0-38a5abac9122#id":{"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/sport\/CompetitiveSportingOrganisation","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"Team GB","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/document":[{"value":"http:\/\/www.bbc.co.uk\/sport\/olympics\/2012\/countries\/great-britain","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/shortName":[{"value":"Great Britain & N. Ireland","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/2012olympics\/territory":[{"value":"http:\/\/www.bbc.co.uk\/things\/d28bb4f7-1446-4aa2-a33e-75cda54d1ee6#id","type":"uri"}]},"http:\/\/www.bbc.co.uk\/things\/d28bb4f7-1446-4aa2-a33e-75cda54d1ee6#id":{"http:\/\/www.bbc.co.uk\/ontologies\/geopolitical\/isInGroup":[{"value":"http:\/\/www.bbc.co.uk\/things\/81b14df8-f9d2-4dff-a676-43a1a9a5c0a5#id","type":"uri"}],"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/geopolitical\/Territory","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"the United Kingdom of Great Britain and Northern Ireland","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}]},"http:\/\/www.bbc.co.uk\/things\/81b14df8-f9d2-4dff-a676-43a1a9a5c0a5#id":{"http:\/\/www.bbc.co.uk\/ontologies\/geopolitical\/groupType":[{"value":"http:\/\/www.bbc.co.uk\/things\/group-types\/bbc-news-geo-regions","type":"uri"}],"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/geopolitical\/Group","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"Europe","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}]},"http:\/\/www.bbc.co.uk\/things\/4e40ce40-b632-4a42-98d7-cf97067f7bf9#id":{"http:\/\/www.bbc.co.uk\/ontologies\/2012olympics\/height":[{"value":"183.0","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#float","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/2012olympics\/gender":[{"value":"M","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"Ben Ainslie","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/sport\/competesIn":[{"value":"http:\/\/www.bbc.co.uk\/things\/8d6ae957-d338-442b-99d7-190f20b78dd4#id","type":"uri"}],"http:\/\/xmlns.com\/foaf\/0.1\/givenName":[{"value":"Ben","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.w3.org\/2000\/01\/rdf-schema#label":[{"value":"Ben Ainslie","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/xmlns.com\/foaf\/0.1\/name":[{"value":"Ben Ainslie","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/canonicalName":[{"value":"Ben Ainslie","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/purl.org\/vocab\/participation\/schema#role_at":[{"value":"http:\/\/www.bbc.co.uk\/things\/7ef7ffdf-f101-4470-adc0-38a5abac9122#id","type":"uri"}],"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/sport\/Person","type":"uri"}],"http:\/\/xmlns.com\/foaf\/0.1\/familyName":[{"value":"Ainslie","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/2012olympics\/weight":[{"value":"90.0","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#float","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/document":[{"value":"http:\/\/www.facebook.com\/pages\/Ben-Ainslie\/108182689201922","type":"uri"},{"value":"http:\/\/www.bbc.co.uk\/sport\/olympics\/2012\/athletes\/4e40ce40-b632-4a42-98d7-cf97067f7bf9","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/2012olympics\/dateOfBirth":[{"value":"1977-02-05","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#date","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/sport\/discipline":[{"value":"http:\/\/www.bbc.co.uk\/things\/d65c5dce-f5e4-4340-931b-16ca1848d092#id","type":"uri"}]},"http:\/\/www.bbc.co.uk\/things\/d65c5dce-f5e4-4340-931b-16ca1848d092#id":{"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/sport\/SportsDiscipline","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"Sailing","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/document":[{"value":"http:\/\/www.bbc.co.uk\/sport\/olympics\/2012\/sports\/sailing","type":"uri"}]},"http:\/\/www.bbc.co.uk\/things\/8d6ae957-d338-442b-99d7-190f20b78dd4#id":{"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/sport\/MedalCompetition","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/name":[{"value":"Men's Finn","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/document":[{"value":"http:\/\/www.bbc.co.uk\/sport\/olympics\/2012\/sports\/sailing\/events\/mens-finn","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/shortName":[{"value":"Men's Finn","datatype":"http:\/\/www.w3.org\/2001\/XMLSchema#string","type":"literal"}]},"http:\/\/www.facebook.com\/pages\/Ben-Ainslie\/108182689201922":{"http:\/\/www.bbc.co.uk\/ontologies\/domain\/documentType":[{"value":"http:\/\/www.bbc.co.uk\/things\/document-types\/external","type":"uri"},{"value":"http:\/\/www.bbc.co.uk\/things\/document-types\/facebook","type":"uri"}],"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/domain\/Document","type":"uri"},{"value":"http:\/\/xmlns.com\/foaf\/0.1\/Document","type":"uri"}]},"http:\/\/www.bbc.co.uk\/sport\/olympics\/2012\/athletes\/4e40ce40-b632-4a42-98d7-cf97067f7bf9":{"http:\/\/www.bbc.co.uk\/ontologies\/domain\/documentType":[{"value":"http:\/\/www.bbc.co.uk\/things\/document-types\/bbc-document","type":"uri"}],"http:\/\/www.bbc.co.uk\/ontologies\/domain\/domain":[{"value":"http:\/\/www.bbc.co.uk\/things\/domains\/olympics2012","type":"uri"}],"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type":[{"value":"http:\/\/www.bbc.co.uk\/ontologies\/domain\/Document","type":"uri"},{"value":"http:\/\/xmlns.com\/foaf\/0.1\/Document","type":"uri"}]}}
@@ -150,4 +150,42 @@ BBCDataService::AppFixture.register_fixture :multiple_items_with_filter, {
150
150
  :value => "Germany",
151
151
  :type => :string
152
152
  }
153
+ }
154
+ BBCDataService::AppFixture.register_fixture :relationship_with_foreign_key, {
155
+ :endpoint => "/dsp/sport/olympics/2012/athletes/4e40ce40-b632-4a42-98d7-cf97067f7bf9",
156
+ :type => :rdf,
157
+ :feed_url => File.expand_path("../athlete.json", __FILE__),
158
+ :rdf_type => "sport:Person",
159
+ :mappings => {
160
+ :foaf => {
161
+ :family_name => "familyName",
162
+ :given_name => "givenName"
163
+ },
164
+ :domain => {
165
+ :name => "name",
166
+ :canonical_name => "canonicalName",
167
+ :url => "document"
168
+ },
169
+ :oly => {
170
+ :date_of_birth => "dateOfBirth",
171
+ :height => "height",
172
+ :weight => "weight",
173
+ :gender => "gender"
174
+ },
175
+ :par => {
176
+ :role_at => "role_at"
177
+ }
178
+ },
179
+ :relationships => {
180
+ :team => {
181
+ :foreign_key => :role_at,
182
+ :rdf_type => "sport:CompetitiveSportingOrganisation",
183
+ :mappings => {
184
+ :domain => {
185
+ :name => "name",
186
+ :short_name => "shortName"
187
+ }
188
+ }
189
+ }
190
+ }
153
191
  }
metadata CHANGED
@@ -1,159 +1,112 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bbc_data_service
3
- version: !ruby/object:Gem::Version
4
- hash: 7
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.5'
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 4
9
- version: "1.4"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Matthew Crouch
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-10-25 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: sinatra
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2164346900 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 19
28
- segments:
29
- - 1
30
- - 2
31
- - 6
20
+ - !ruby/object:Gem::Version
32
21
  version: 1.2.6
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: activesupport
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2164346900
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &2164346320 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 3
46
- - 1
47
- - 0
31
+ - !ruby/object:Gem::Version
48
32
  version: 3.1.0
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: activemodel
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2164346320
36
+ - !ruby/object:Gem::Dependency
37
+ name: activemodel
38
+ requirement: &2164345740 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
40
+ requirements:
57
41
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 3
62
- - 1
63
- - 0
42
+ - !ruby/object:Gem::Version
64
43
  version: 3.1.0
65
44
  type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rdf-json
69
45
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2164345740
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdf-json
49
+ requirement: &2164345240 !ruby/object:Gem::Requirement
71
50
  none: false
72
- requirements:
51
+ requirements:
73
52
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 19
76
- segments:
77
- - 0
78
- - 3
79
- - 0
53
+ - !ruby/object:Gem::Version
80
54
  version: 0.3.0
81
55
  type: :runtime
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: nokogiri
85
56
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2164345240
58
+ - !ruby/object:Gem::Dependency
59
+ name: nokogiri
60
+ requirement: &2156478960 !ruby/object:Gem::Requirement
87
61
  none: false
88
- requirements:
89
- - - "="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 1
94
- - 5
95
- - 0
62
+ requirements:
63
+ - - =
64
+ - !ruby/object:Gem::Version
96
65
  version: 1.5.0
97
66
  type: :runtime
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: rspec
101
67
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2156478960
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &2156478240 !ruby/object:Gem::Requirement
103
72
  none: false
104
- requirements:
73
+ requirements:
105
74
  - - ~>
106
- - !ruby/object:Gem::Version
107
- hash: 23
108
- segments:
109
- - 2
110
- - 6
111
- - 0
75
+ - !ruby/object:Gem::Version
112
76
  version: 2.6.0
113
77
  type: :development
114
- version_requirements: *id006
115
- - !ruby/object:Gem::Dependency
116
- name: turn
117
78
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *2156478240
80
+ - !ruby/object:Gem::Dependency
81
+ name: turn
82
+ requirement: &2156477560 !ruby/object:Gem::Requirement
119
83
  none: false
120
- requirements:
84
+ requirements:
121
85
  - - ~>
122
- - !ruby/object:Gem::Version
123
- hash: 59
124
- segments:
125
- - 0
126
- - 8
127
- - 2
86
+ - !ruby/object:Gem::Version
128
87
  version: 0.8.2
129
88
  type: :development
130
- version_requirements: *id007
131
- - !ruby/object:Gem::Dependency
132
- name: rake
133
89
  prerelease: false
134
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *2156477560
91
+ - !ruby/object:Gem::Dependency
92
+ name: rake
93
+ requirement: &2156476840 !ruby/object:Gem::Requirement
135
94
  none: false
136
- requirements:
95
+ requirements:
137
96
  - - ~>
138
- - !ruby/object:Gem::Version
139
- hash: 63
140
- segments:
141
- - 0
142
- - 9
143
- - 2
97
+ - !ruby/object:Gem::Version
144
98
  version: 0.9.2
145
99
  type: :development
146
- version_requirements: *id008
100
+ prerelease: false
101
+ version_requirements: *2156476840
147
102
  description: BBC Data Service for fixture management
148
- email:
103
+ email:
149
104
  - matthew.crouch@bbc.co.uk
150
- executables:
105
+ executables:
151
106
  - bbc_data_service
152
107
  extensions: []
153
-
154
108
  extra_rdoc_files: []
155
-
156
- files:
109
+ files:
157
110
  - .gitignore
158
111
  - Gemfile
159
112
  - Rakefile
@@ -171,6 +124,7 @@ files:
171
124
  - lib/bbc_data_service/vocabulary.rb
172
125
  - lib/bbc_data_service/xml_parser.rb
173
126
  - spec/fixture_loader_spec.rb
127
+ - spec/fixtures/athlete.json
174
128
  - spec/fixtures/countries.rdf.json
175
129
  - spec/fixtures/country.rdf.json
176
130
  - spec/fixtures/groups-individual.json
@@ -181,39 +135,31 @@ files:
181
135
  - spec/spec_helper.rb
182
136
  homepage: https://github.com/mobzilla/bbc-data-service
183
137
  licenses: []
184
-
185
138
  post_install_message:
186
139
  rdoc_options: []
187
-
188
- require_paths:
140
+ require_paths:
189
141
  - lib
190
- required_ruby_version: !ruby/object:Gem::Requirement
142
+ required_ruby_version: !ruby/object:Gem::Requirement
191
143
  none: false
192
- requirements:
193
- - - ">="
194
- - !ruby/object:Gem::Version
195
- hash: 3
196
- segments:
197
- - 0
198
- version: "0"
199
- required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
149
  none: false
201
- requirements:
202
- - - ">="
203
- - !ruby/object:Gem::Version
204
- hash: 3
205
- segments:
206
- - 0
207
- version: "0"
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
208
154
  requirements: []
209
-
210
155
  rubyforge_project: bbc-data-service
211
156
  rubygems_version: 1.8.10
212
157
  signing_key:
213
158
  specification_version: 3
214
159
  summary: BBC Data Service
215
- test_files:
160
+ test_files:
216
161
  - spec/fixture_loader_spec.rb
162
+ - spec/fixtures/athlete.json
217
163
  - spec/fixtures/countries.rdf.json
218
164
  - spec/fixtures/country.rdf.json
219
165
  - spec/fixtures/groups-individual.json