hdo-storting-importer 0.0.8 → 0.0.9

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 (50) hide show
  1. data/Gemfile +1 -1
  2. data/Rakefile +0 -1
  3. data/features/convert.feature +97 -79
  4. data/hdo-storting-importer.gemspec +5 -0
  5. data/lib/hdo/storting_importer/category.rb +16 -56
  6. data/lib/hdo/storting_importer/cli.rb +6 -34
  7. data/lib/hdo/storting_importer/committee.rb +13 -24
  8. data/lib/hdo/storting_importer/converter.rb +4 -9
  9. data/lib/hdo/storting_importer/district.rb +12 -24
  10. data/lib/hdo/storting_importer/fusion_table.rb +52 -0
  11. data/lib/hdo/storting_importer/has_json_schema.rb +85 -0
  12. data/lib/hdo/storting_importer/issue.rb +29 -60
  13. data/lib/hdo/storting_importer/party.rb +13 -24
  14. data/lib/hdo/storting_importer/promise.rb +60 -55
  15. data/lib/hdo/storting_importer/proposition.rb +61 -0
  16. data/lib/hdo/storting_importer/representative.rb +37 -70
  17. data/lib/hdo/storting_importer/schema/category.json +28 -0
  18. data/lib/hdo/storting_importer/schema/committee.json +21 -0
  19. data/lib/hdo/storting_importer/schema/district.json +21 -0
  20. data/lib/hdo/storting_importer/schema/issue.json +62 -0
  21. data/lib/hdo/storting_importer/schema/party.json +21 -0
  22. data/lib/hdo/storting_importer/schema/promise.json +42 -0
  23. data/lib/hdo/storting_importer/schema/proposition.json +34 -0
  24. data/lib/hdo/storting_importer/schema/representative.json +61 -0
  25. data/lib/hdo/storting_importer/schema/vote.json +64 -0
  26. data/lib/hdo/storting_importer/schema.json +5 -0
  27. data/lib/hdo/storting_importer/util.rb +13 -11
  28. data/lib/hdo/storting_importer/version.rb +1 -1
  29. data/lib/hdo/storting_importer/vote.rb +46 -143
  30. data/lib/hdo/storting_importer.rb +12 -3
  31. data/spec/fixtures/output/categories.json +1 -0
  32. data/spec/fixtures/output/committees.json +1 -0
  33. data/spec/fixtures/output/districts.json +1 -0
  34. data/spec/fixtures/output/issues.json +1 -0
  35. data/spec/fixtures/output/parties.json +1 -0
  36. data/spec/fixtures/output/representatives.json +1 -0
  37. data/spec/fixtures/output/votes.json +1 -0
  38. data/spec/hdo/storting_importer/category_spec.rb +29 -33
  39. data/spec/hdo/storting_importer/committee_spec.rb +29 -16
  40. data/spec/hdo/storting_importer/converter_spec.rb +3 -3
  41. data/spec/hdo/storting_importer/district_spec.rb +27 -18
  42. data/spec/hdo/storting_importer/issue_spec.rb +44 -27
  43. data/spec/hdo/storting_importer/party_spec.rb +25 -16
  44. data/spec/hdo/storting_importer/promise_spec.rb +54 -40
  45. data/spec/hdo/storting_importer/proposition_spec.rb +44 -0
  46. data/spec/hdo/storting_importer/representative_spec.rb +73 -26
  47. data/spec/hdo/storting_importer/vote_spec.rb +73 -75
  48. data/spec/spec_helper.rb +21 -1
  49. metadata +95 -3
  50. data/.gitmodules +0 -3
@@ -72,90 +72,92 @@ module Hdo
72
72
  vote.counts.absent.should == 71
73
73
  end
74
74
 
75
- it 'can serialize as HDO XML' do
76
- vote = Vote.example
77
- vote.to_hdo_xml.should == <<-XML
78
- <vote>
79
- <externalId>2175</externalId>
80
- <externalIssueId>51448</externalIssueId>
81
- <counts>
82
- <for>2</for>
83
- <against>96</against>
84
- <absent>71</absent>
85
- </counts>
86
- <personal>true</personal>
87
- <enacted>false</enacted>
88
- <subject>Forslag 24 - 26 på vegne av Per Olaf Lundteigen</subject>
89
- <method>ikke_spesifisert</method>
90
- <resultType>ikke_spesifisert</resultType>
91
- <time>2012-04-12T16:37:27.053</time>
92
- <representatives>
93
- <representative>
94
- <externalId>ADA</externalId>
95
- <firstName>André Oktay</firstName>
96
- <lastName>Dahl</lastName>
97
- <gender>M</gender>
98
- <dateOfBirth>1975-07-07T00:00:00</dateOfBirth>
99
- <dateOfDeath>0001-01-01T00:00:00</dateOfDeath>
100
- <district>Akershus</district>
101
- <party>Høyre</party>
102
- <committees>
103
- <committee>Justiskomiteen</committee>
104
- </committees>
105
- <period>2011-2012</period>
106
- <voteResult>for</voteResult>
107
- </representative>
108
- </representatives>
109
- <propositions>
110
- <proposition>
111
- <externalId>1234</externalId>
112
- <description>description</description>
113
- <onBehalfOf>on behalf of</onBehalfOf>
114
- <body>body</body>
115
- <deliveredBy>
116
- <representative>
117
- <externalId>ADA</externalId>
118
- <firstName>André Oktay</firstName>
119
- <lastName>Dahl</lastName>
120
- <gender>M</gender>
121
- <dateOfBirth>1975-07-07T00:00:00</dateOfBirth>
122
- <dateOfDeath>0001-01-01T00:00:00</dateOfDeath>
123
- <district>Akershus</district>
124
- <party>Høyre</party>
125
- <committees>
126
- <committee>Justiskomiteen</committee>
127
- </committees>
128
- <period>2011-2012</period>
129
- </representative>
130
- </deliveredBy>
131
- </proposition>
132
- </propositions>
133
- </vote>
134
- XML
75
+ it 'can serialize as JSON' do
76
+ Vote.example.to_json.should be_json <<-JSON
77
+ {
78
+ "kind": "hdo#vote",
79
+ "externalId": "2175",
80
+ "externalIssueId": "51448",
81
+ "counts": {
82
+ "for": 2,
83
+ "against": 96,
84
+ "absent": 71
85
+ },
86
+ "personal": true,
87
+ "enacted": false,
88
+ "subject": "Forslag 24 - 26 på vegne av Per Olaf Lundteigen",
89
+ "method": "ikke_spesifisert",
90
+ "resultType": "ikke_spesifisert",
91
+ "time": "2012-04-12T16:37:27.053",
92
+ "representatives": [
93
+ {
94
+ "kind": "hdo#representative",
95
+ "externalId": "ADA",
96
+ "firstName": "André Oktay",
97
+ "lastName": "Dahl",
98
+ "gender": "M",
99
+ "dateOfBirth": "1975-07-07T00:00:00",
100
+ "dateOfDeath": "0001-01-01T00:00:00",
101
+ "district": "Akershus",
102
+ "party": "Høyre",
103
+ "committees": ["Justiskomiteen"],
104
+ "period": "2011-2012",
105
+ "voteResult": "for"
106
+ }
107
+ ],
108
+ "propositions": [
109
+ {
110
+ "kind": "hdo#proposition",
111
+ "externalId": "1234",
112
+ "description": "description",
113
+ "onBehalfOf": "on behalf of",
114
+ "body": "body",
115
+ "deliveredBy": {
116
+ "kind": "hdo#representative",
117
+ "externalId": "ADA",
118
+ "firstName": "André Oktay",
119
+ "lastName": "Dahl",
120
+ "gender": "M",
121
+ "dateOfBirth": "1975-07-07T00:00:00",
122
+ "dateOfDeath": "0001-01-01T00:00:00",
123
+ "district": "Akershus",
124
+ "party": "Høyre",
125
+ "committees": ["Justiskomiteen"],
126
+ "period": "2011-2012"
127
+ }
128
+ }
129
+ ]
130
+ }
131
+ JSON
135
132
  end
136
133
 
137
- it 'can deserialize a HDO XML node' do
134
+ it 'can deserialize JSON' do
138
135
  orig = Vote.example
139
- Vote.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
136
+ Vote.from_json(orig.to_json).should == orig
140
137
  end
141
138
 
142
- it 'can deserialize a HDO XML doc' do
143
- orig = Vote.example
144
- Vote.from_hdo_doc(parse("<votes>#{orig.to_hdo_xml}</votes>")).should == [orig]
139
+ it 'can deserialize a JSON array' do
140
+ orig = [Vote.example]
141
+ Vote.from_json(orig.to_json).should == orig
142
+ end
143
+
144
+ it 'fails if the given JSON is invalid' do
145
+ json = Vote.example.to_hash
146
+ json.delete :personal
147
+
148
+ expect { Vote.from_json(json.to_json) }.to raise_error(ValidationError)
145
149
  end
146
150
 
147
- it 'has a type name' do
148
- Vote.type_name.should == 'vote'
149
- Vote::Proposition.type_name.should == 'proposition'
151
+ it 'has a kind' do
152
+ Vote.kind.should == 'hdo#vote'
150
153
  end
151
154
 
152
155
  it 'has a description' do
153
156
  Vote.description.should be_kind_of(String)
154
157
  end
155
158
 
156
- it 'has an XML example' do
157
- Vote.xml_example.should be_kind_of(String)
158
- Vote::Proposition.xml_example.should be_kind_of(String)
159
+ it 'has a JSON example' do
160
+ Vote.json_example.should be_kind_of(String)
159
161
  end
160
162
 
161
163
  it 'has a list of fields' do
@@ -164,10 +166,6 @@ module Hdo
164
166
 
165
167
  it 'has #short_inspect' do
166
168
  Vote.example.short_inspect.should be_kind_of(String)
167
-
168
- str = Vote::Proposition.example.short_inspect
169
- str.should be_kind_of(String)
170
- str.should_not include("nil")
171
169
  end
172
170
 
173
171
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rspec'
2
2
  require 'hdo/storting_importer'
3
+ require 'pry'
3
4
  require 'pp'
4
5
 
5
6
  module Hdo
@@ -12,7 +13,7 @@ module Hdo
12
13
  end
13
14
 
14
15
  def output_fixture(name)
15
- FIXTURES.join(output_path("#{name}.xml")).read
16
+ FIXTURES.join(output_path("#{name}.json")).read
16
17
  end
17
18
 
18
19
  def input_path(filename)
@@ -30,6 +31,25 @@ module Hdo
30
31
  doc
31
32
  end
32
33
 
34
+ class EqualsJson
35
+ def initialize(expected)
36
+ @expected = MultiJson.decode(expected)
37
+ end
38
+ def matches?(target)
39
+ @target = MultiJson.decode(target)
40
+ @target.eql?(@expected)
41
+ end
42
+ def failure_message
43
+ "expected #{@target.inspect} to be #{@expected}"
44
+ end
45
+ def negative_failure_message
46
+ "expected #{@target.inspect} not to be #{@expected}"
47
+ end
48
+ end
49
+
50
+ def be_json(expected)
51
+ EqualsJson.new(expected)
52
+ end
33
53
  end
34
54
  end
35
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdo-storting-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
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: 2012-08-04 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -123,6 +123,70 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yajl-ruby
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: jschematic
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 0.1.0
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 0.1.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: pry
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: rspec
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
126
190
  description: Gem to process data from data.stortinget.no
127
191
  email:
128
192
  - jari.bakken@gmail.com
@@ -132,7 +196,6 @@ extensions: []
132
196
  extra_rdoc_files: []
133
197
  files:
134
198
  - .gitignore
135
- - .gitmodules
136
199
  - .travis.yml
137
200
  - Gemfile
138
201
  - LICENSE
@@ -152,13 +215,26 @@ files:
152
215
  - lib/hdo/storting_importer/data_source.rb
153
216
  - lib/hdo/storting_importer/disk_data_source.rb
154
217
  - lib/hdo/storting_importer/district.rb
218
+ - lib/hdo/storting_importer/fusion_table.rb
219
+ - lib/hdo/storting_importer/has_json_schema.rb
155
220
  - lib/hdo/storting_importer/inspectable.rb
156
221
  - lib/hdo/storting_importer/issue.rb
157
222
  - lib/hdo/storting_importer/ivar_equality.rb
158
223
  - lib/hdo/storting_importer/parsing_data_source.rb
159
224
  - lib/hdo/storting_importer/party.rb
160
225
  - lib/hdo/storting_importer/promise.rb
226
+ - lib/hdo/storting_importer/proposition.rb
161
227
  - lib/hdo/storting_importer/representative.rb
228
+ - lib/hdo/storting_importer/schema.json
229
+ - lib/hdo/storting_importer/schema/category.json
230
+ - lib/hdo/storting_importer/schema/committee.json
231
+ - lib/hdo/storting_importer/schema/district.json
232
+ - lib/hdo/storting_importer/schema/issue.json
233
+ - lib/hdo/storting_importer/schema/party.json
234
+ - lib/hdo/storting_importer/schema/promise.json
235
+ - lib/hdo/storting_importer/schema/proposition.json
236
+ - lib/hdo/storting_importer/schema/representative.json
237
+ - lib/hdo/storting_importer/schema/vote.json
162
238
  - lib/hdo/storting_importer/util.rb
163
239
  - lib/hdo/storting_importer/version.rb
164
240
  - lib/hdo/storting_importer/vote.rb
@@ -175,13 +251,20 @@ files:
175
251
  - spec/fixtures/input/vote_results_2175.xml
176
252
  - spec/fixtures/input/vote_results_2176.xml
177
253
  - spec/fixtures/input/votes.xml
254
+ - spec/fixtures/output/categories.json
178
255
  - spec/fixtures/output/categories.xml
256
+ - spec/fixtures/output/committees.json
179
257
  - spec/fixtures/output/committees.xml
258
+ - spec/fixtures/output/districts.json
180
259
  - spec/fixtures/output/districts.xml
260
+ - spec/fixtures/output/issues.json
181
261
  - spec/fixtures/output/issues.xml
262
+ - spec/fixtures/output/parties.json
182
263
  - spec/fixtures/output/parties.xml
183
264
  - spec/fixtures/output/promises-a.xml
265
+ - spec/fixtures/output/representatives.json
184
266
  - spec/fixtures/output/representatives.xml
267
+ - spec/fixtures/output/votes.json
185
268
  - spec/fixtures/output/votes.xml
186
269
  - spec/hdo/storting_importer/category_spec.rb
187
270
  - spec/hdo/storting_importer/committee_spec.rb
@@ -190,6 +273,7 @@ files:
190
273
  - spec/hdo/storting_importer/issue_spec.rb
191
274
  - spec/hdo/storting_importer/party_spec.rb
192
275
  - spec/hdo/storting_importer/promise_spec.rb
276
+ - spec/hdo/storting_importer/proposition_spec.rb
193
277
  - spec/hdo/storting_importer/representative_spec.rb
194
278
  - spec/hdo/storting_importer/vote_spec.rb
195
279
  - spec/spec_helper.rb
@@ -233,13 +317,20 @@ test_files:
233
317
  - spec/fixtures/input/vote_results_2175.xml
234
318
  - spec/fixtures/input/vote_results_2176.xml
235
319
  - spec/fixtures/input/votes.xml
320
+ - spec/fixtures/output/categories.json
236
321
  - spec/fixtures/output/categories.xml
322
+ - spec/fixtures/output/committees.json
237
323
  - spec/fixtures/output/committees.xml
324
+ - spec/fixtures/output/districts.json
238
325
  - spec/fixtures/output/districts.xml
326
+ - spec/fixtures/output/issues.json
239
327
  - spec/fixtures/output/issues.xml
328
+ - spec/fixtures/output/parties.json
240
329
  - spec/fixtures/output/parties.xml
241
330
  - spec/fixtures/output/promises-a.xml
331
+ - spec/fixtures/output/representatives.json
242
332
  - spec/fixtures/output/representatives.xml
333
+ - spec/fixtures/output/votes.json
243
334
  - spec/fixtures/output/votes.xml
244
335
  - spec/hdo/storting_importer/category_spec.rb
245
336
  - spec/hdo/storting_importer/committee_spec.rb
@@ -248,6 +339,7 @@ test_files:
248
339
  - spec/hdo/storting_importer/issue_spec.rb
249
340
  - spec/hdo/storting_importer/party_spec.rb
250
341
  - spec/hdo/storting_importer/promise_spec.rb
342
+ - spec/hdo/storting_importer/proposition_spec.rb
251
343
  - spec/hdo/storting_importer/representative_spec.rb
252
344
  - spec/hdo/storting_importer/vote_spec.rb
253
345
  - spec/spec_helper.rb
data/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "folketingparser"]
2
- path = folketingparser
3
- url = git://gitorious.org/nuug/folketingparser.git