hdo-storting-importer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
- guard 'rspec', :version => 2 do
3
+ guard 'rspec' do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
5
  watch(%r{^spec/fixtures})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
@@ -58,6 +58,14 @@ module Hdo
58
58
  fetch "eksport/fylker"
59
59
  end
60
60
 
61
+ def parliament_periods
62
+ fetch "eksport/stortingsperioder"
63
+ end
64
+
65
+ def parliament_sessions
66
+ fetch "eksport/sesjoner"
67
+ end
68
+
61
69
  def categories
62
70
  fetch "eksport/emner"
63
71
  end
@@ -22,6 +22,14 @@ module Hdo
22
22
  fetch "eksport/emner/index.html"
23
23
  end
24
24
 
25
+ def parliament_periods
26
+ fetch "eksport/stortingsperioder"
27
+ end
28
+
29
+ def parliament_sessions
30
+ fetch "eksport/sesjoner"
31
+ end
32
+
25
33
  def parliament_issues(session_id)
26
34
  fetch "eksport/saker/index.html?sesjonid=#{session_id}"
27
35
  end
@@ -2,9 +2,11 @@ module Hdo
2
2
  module StortingImporter
3
3
  class GoverningPeriod
4
4
  include IvarEquality
5
+ include HasJsonSchema
5
6
 
6
7
  attr_reader :start_date, :end_date
7
8
 
9
+ schema_path StortingImporter.lib.join("hdo/storting_importer/schema/governing_period.json").to_s
8
10
 
9
11
  def self.add_to(parties)
10
12
  Array(parties).each do |party|
@@ -25,19 +27,24 @@ module Hdo
25
27
  }
26
28
  end
27
29
 
30
+ def self.example
31
+ all['A'].first
32
+ end
33
+
28
34
  def self.from_hash(hash)
29
35
  new hash['startDate'], hash['endDate']
30
36
  end
31
37
 
32
38
  def initialize(start_date, end_date = nil)
33
- @start_date = Date.strptime(start_date)
39
+ @start_date = Date.strptime(start_date) if start_date
34
40
  @end_date = Date.strptime(end_date) if end_date
35
41
  end
36
42
 
37
43
  def to_hash
38
44
  {
39
- 'startDate' => @start_date.iso8601,
40
- 'endDate' => @end_date && @end_date.iso8601
45
+ 'kind' => self.class.kind,
46
+ 'startDate' => @start_date && @start_date.iso8601,
47
+ 'endDate' => @end_date && @end_date.iso8601
41
48
  }
42
49
  end
43
50
 
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ module Hdo
4
+ module StortingImporter
5
+ class ParliamentPeriod
6
+ include HasJsonSchema
7
+ include IvarEquality
8
+
9
+ attr_reader :external_id, :start_date, :end_date
10
+
11
+ schema_path StortingImporter.lib.join("hdo/storting_importer/schema/parliament_period.json").to_s
12
+
13
+ def self.from_storting_doc(doc)
14
+ doc.css('stortingsperioder_liste stortingsperiode').map do |node|
15
+ from_storting_node(node)
16
+ end
17
+ end
18
+
19
+ def self.from_storting_node(node)
20
+ new node.css("id").text,
21
+ Date.parse(node.css("fra").text),
22
+ Date.parse(node.css("til").text)
23
+ end
24
+
25
+ def self.from_hash(hash)
26
+ new hash['externalId'],
27
+ hash['startDate'] && Date.parse(hash['startDate']),
28
+ hash['endDate'] && Date.parse(hash['endDate'])
29
+ end
30
+
31
+ def self.example(overrides = nil)
32
+ obj = new('2009-2013', Date.parse('2009-10-01'), Date.parse('2013-09-30'))
33
+
34
+ if overrides
35
+ obj = from_hash(obj.to_hash.merge(overrides))
36
+ end
37
+
38
+ obj
39
+ end
40
+
41
+ def initialize(external_id, start_date, end_date)
42
+ @external_id = external_id
43
+ @start_date = start_date
44
+ @end_date = end_date
45
+ end
46
+
47
+ def to_hash
48
+ {
49
+ 'kind' => self.class.kind,
50
+ 'externalId' => @external_id,
51
+ 'startDate' => @start_date && @start_date.iso8601,
52
+ 'endDate' => @end_date && @end_date.iso8601
53
+ }
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ module Hdo
4
+ module StortingImporter
5
+ class ParliamentSession
6
+ include HasJsonSchema
7
+ include IvarEquality
8
+
9
+ attr_reader :external_id, :start_date, :end_date
10
+
11
+ schema_path StortingImporter.lib.join("hdo/storting_importer/schema/parliament_session.json").to_s
12
+
13
+ def self.from_storting_doc(doc)
14
+ doc.css("sesjoner_liste sesjon").map do |node|
15
+ from_storting_node node
16
+ end
17
+ end
18
+
19
+ def self.from_storting_node(node)
20
+ new node.css("id").text,
21
+ Date.parse(node.css("fra").text),
22
+ Date.parse(node.css("til").text)
23
+ end
24
+
25
+ def self.from_hash(hash)
26
+ new hash['externalId'],
27
+ hash['startDate'] && Date.parse(hash['startDate']),
28
+ hash['endDate'] && Date.parse(hash['endDate'])
29
+ end
30
+
31
+ def self.example(overrides = nil)
32
+ obj = new('2012-2013', Date.parse('2012-10-01'), Date.parse('2013-09-30'))
33
+
34
+ if overrides
35
+ obj = from_hash(obj.to_hash.merge(overrides))
36
+ end
37
+
38
+ obj
39
+ end
40
+
41
+ def initialize(external_id, start_date, end_date)
42
+ @external_id = external_id
43
+ @start_date = start_date
44
+ @end_date = end_date
45
+ end
46
+
47
+ def to_hash
48
+ {
49
+ 'kind' => self.class.kind,
50
+ 'externalId' => @external_id,
51
+ 'startDate' => @start_date && @start_date.iso8601,
52
+ 'endDate' => @end_date && @end_date.iso8601
53
+ }
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -25,6 +25,14 @@ module Hdo
25
25
  District.from_storting_doc @data_source.districts
26
26
  end
27
27
 
28
+ def parliament_periods
29
+ ParliamentPeriod.from_storting_doc @data_source.parliament_periods
30
+ end
31
+
32
+ def parliament_sessions
33
+ ParliamentSession.from_storting_doc @data_source.parliament_sessions
34
+ end
35
+
28
36
  def categories
29
37
  Category.from_storting_doc @data_source.categories
30
38
  end
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "hdo#governingPeriod",
3
+ "description": "a period where a party is in government",
4
+ "type":"object",
5
+ "properties": {
6
+ "kind": {
7
+ "type": "string",
8
+ "description": "This is always 'hdo#governingPeriod'",
9
+ "default": "hdo#governingPeriod",
10
+ "required": true
11
+ },
12
+ "startDate": {
13
+ "type": "string",
14
+ "description": "The date the period started.",
15
+ "format": "date",
16
+ "required": true
17
+ },
18
+ "endDate": {
19
+ "type": "string",
20
+ "description": "The date the period ended. Can be null if the period is current.",
21
+ "format": "date",
22
+ "required": false
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "hdo#parliamentPeriod",
3
+ "description": "Object representing the period between elections.",
4
+ "type":"object",
5
+ "properties": {
6
+ "kind": {
7
+ "type": "string",
8
+ "description": "This is always 'hdo#parliamentPeriod'",
9
+ "default": "hdo#parliamentPeriod",
10
+ "required": true
11
+ },
12
+ "startDate": {
13
+ "type": "string",
14
+ "description": "The date the period started.",
15
+ "format": "date",
16
+ "required": true
17
+ },
18
+ "endDate": {
19
+ "type": "string",
20
+ "description": "The date the period ended.",
21
+ "format": "date",
22
+ "required": true
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "hdo#parliamentSession",
3
+ "description": "Object representing the parliamentary year.",
4
+ "type":"object",
5
+ "properties": {
6
+ "kind": {
7
+ "type": "string",
8
+ "description": "This is always 'hdo#parliamentSession'",
9
+ "default": "hdo#parliamentSession",
10
+ "required": true
11
+ },
12
+ "startDate": {
13
+ "type": "string",
14
+ "description": "The date the period started.",
15
+ "format": "date",
16
+ "required": true
17
+ },
18
+ "endDate": {
19
+ "type": "string",
20
+ "description": "The date the period ended.",
21
+ "format": "date",
22
+ "required": true
23
+ }
24
+ }
@@ -1,5 +1,5 @@
1
1
  module Hdo
2
2
  module StortingImporter
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -26,15 +26,20 @@ module Hdo
26
26
 
27
27
  def self.types
28
28
  [
29
- Party,
29
+ Category,
30
30
  Committee,
31
+ CommitteeMembership,
31
32
  District,
33
+ GoverningPeriod,
34
+ ParliamentIssue,
35
+ ParliamentSession,
36
+ ParliamentPeriod,
37
+ Party,
38
+ PartyMembership,
39
+ Promise,
40
+ Proposition,
32
41
  Representative,
33
- Category,
34
- Issue,
35
42
  Vote,
36
- Proposition,
37
- Promise
38
43
  ]
39
44
  end
40
45
 
@@ -125,6 +130,8 @@ require 'hdo/storting_importer/committee'
125
130
  require 'hdo/storting_importer/committee_membership'
126
131
  require 'hdo/storting_importer/district'
127
132
  require 'hdo/storting_importer/parliament_issue'
133
+ require 'hdo/storting_importer/parliament_period'
134
+ require 'hdo/storting_importer/parliament_session'
128
135
  require 'hdo/storting_importer/party'
129
136
  require 'hdo/storting_importer/party_membership'
130
137
  require 'hdo/storting_importer/promise'
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ module Hdo
5
+ module StortingImporter
6
+ describe GoverningPeriod do
7
+
8
+ it_behaves_like 'type with JSON schema'
9
+
10
+ it 'can serialize as JSON' do
11
+ expected = <<-JSON
12
+ {
13
+ "kind": "hdo#governingPeriod",
14
+ "startDate": "2005-10-01",
15
+ "endDate": "2013-09-30"
16
+ }
17
+ JSON
18
+
19
+ session = GoverningPeriod.new('2005-10-01', '2013-09-30')
20
+ session.to_json.should be_json(expected)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ module Hdo
5
+ module StortingImporter
6
+ describe ParliamentPeriod do
7
+
8
+ it_behaves_like 'type with JSON schema'
9
+
10
+ it 'builds parliament periods from Storting XML list' do
11
+ xml = <<-XML
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <stortingsperioder_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
14
+ <versjon>1.0</versjon
15
+ <innevaerende_stortingsperiode>
16
+ <versjon>1.0</versjon
17
+ <fra>2009-10-01T00:00:00</fra
18
+ <id>2009-2013</id
19
+ <til>2013-09-30T23:59:59</til
20
+ </innevaerende_stortingsperiode>
21
+ <stortingsperioder_liste>
22
+ <stortingsperiode>
23
+ <versjon>1.0</versjon>
24
+ <fra>2009-10-01T00:00:00</fra>
25
+ <id>2009-2013</id>
26
+ <til>2013-09-30T23:59:59</til>
27
+ </stortingsperiode>
28
+ <stortingsperiode>
29
+ <versjon>1.0</versjon>
30
+ <fra>2005-10-01T00:00:00</fra>
31
+ <id>2005-2009</id>
32
+ <til>2009-09-30T23:59:59</til>
33
+ </stortingsperiode>
34
+ </stortingsperioder_liste>
35
+ </stortingsperioder_oversikt>
36
+ XML
37
+
38
+ periods = ParliamentPeriod.from_storting_doc(parse(xml))
39
+
40
+ # we ignore the 'current period', which can be inferred from the current date
41
+ periods.size.should == 2
42
+
43
+ period = periods.first
44
+
45
+ period.external_id.should == '2009-2013'
46
+ period.start_date.should == Date.parse('2009-10-01')
47
+ period.end_date.should == Date.parse('2013-09-30')
48
+ end
49
+
50
+ it 'can serialize as JSON' do
51
+ expected = <<-JSON
52
+ {
53
+ "kind": "hdo#parliamentPeriod",
54
+ "externalId": "2009-2013",
55
+ "startDate": "2009-10-01",
56
+ "endDate": "2013-09-30"
57
+ }
58
+ JSON
59
+
60
+ period = ParliamentPeriod.new("2009-2013", Date.parse('2009-10-01'), Date.parse('2013-09-30'))
61
+ period.to_json.should be_json(expected)
62
+ end
63
+
64
+ it 'can create a customized example' do
65
+ obj = ParliamentPeriod.example('endDate' => nil)
66
+ obj.end_date.should be_nil
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ module Hdo
5
+ module StortingImporter
6
+ describe ParliamentSession do
7
+
8
+ it_behaves_like 'type with JSON schema'
9
+
10
+ it 'builds parliament sessions from Storting XML list' do
11
+ xml = <<-XML
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <sesjoner_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
14
+ <versjon>1.0</versjon>
15
+ <innevaerende_sesjon>
16
+ <versjon>1.0</versjon>
17
+ <fra>2012-10-01T00:00:00</fra>
18
+ <id>2012-2013</id>
19
+ <til>2013-09-30T23:59:59</til>
20
+ </innevaerende_sesjon>
21
+ <sesjoner_liste>
22
+ <sesjon>
23
+ <versjon>1.0</versjon>
24
+ <fra>2012-10-01T00:00:00</fra>
25
+ <id>2012-2013</id>
26
+ <til>2013-09-30T23:59:59</til>
27
+ </sesjon>
28
+ <sesjon>
29
+ <versjon>1.0</versjon>
30
+ <fra>2011-10-01T00:00:00</fra>
31
+ <id>2011-2012</id>
32
+ <til>2012-09-30T23:59:59</til>
33
+ </sesjon>
34
+ </sesjoner_liste>
35
+ </sesjoner_oversikt>
36
+ XML
37
+
38
+ sessions = ParliamentSession.from_storting_doc(parse(xml))
39
+ sessions.size.should == 2
40
+
41
+ session = sessions.first
42
+
43
+ session.external_id.should == '2012-2013'
44
+ session.start_date.should == Date.parse('2012-10-01')
45
+ session.end_date.should == Date.parse('2013-09-30')
46
+ end
47
+
48
+ it 'can serialize as JSON' do
49
+ expected = <<-JSON
50
+ {
51
+ "kind": "hdo#parliamentSession",
52
+ "externalId": "2012-2013",
53
+ "startDate": "2012-10-01",
54
+ "endDate": "2013-09-30"
55
+ }
56
+ JSON
57
+
58
+ session = ParliamentSession.new("2012-2013", Date.parse('2012-10-01'), Date.parse('2013-09-30'))
59
+ session.to_json.should be_json(expected)
60
+ end
61
+
62
+ it 'can create a customized example' do
63
+ obj = ParliamentSession.example('endDate' => nil)
64
+ obj.end_date.should be_nil
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -42,7 +42,11 @@ module Hdo
42
42
  "externalId": "A",
43
43
  "name": "Arbeiderpartiet",
44
44
  "governingPeriods": [
45
- { "startDate": "2005-10-17", "endDate": "2013-10-14" }
45
+ {
46
+ "kind": "hdo#governingPeriod",
47
+ "startDate": "2005-10-17",
48
+ "endDate": "2013-10-14"
49
+ }
46
50
  ]
47
51
  }
48
52
  JSON
data/spec/spec_helper.rb CHANGED
@@ -54,5 +54,6 @@ module Hdo
54
54
  end
55
55
 
56
56
  RSpec.configure do |c|
57
+ c.color = $stdout.tty?
57
58
  c.include Hdo::StortingImporter::SpecHelper
58
59
  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.3.0
4
+ version: 0.3.1
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-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -303,6 +303,8 @@ files:
303
303
  - lib/hdo/storting_importer/inspectable.rb
304
304
  - lib/hdo/storting_importer/ivar_equality.rb
305
305
  - lib/hdo/storting_importer/parliament_issue.rb
306
+ - lib/hdo/storting_importer/parliament_period.rb
307
+ - lib/hdo/storting_importer/parliament_session.rb
306
308
  - lib/hdo/storting_importer/parsing_data_source.rb
307
309
  - lib/hdo/storting_importer/party.rb
308
310
  - lib/hdo/storting_importer/party_membership.rb
@@ -314,7 +316,10 @@ files:
314
316
  - lib/hdo/storting_importer/schema/committee.json
315
317
  - lib/hdo/storting_importer/schema/committee_membership.json
316
318
  - lib/hdo/storting_importer/schema/district.json
319
+ - lib/hdo/storting_importer/schema/governing_period.json
317
320
  - lib/hdo/storting_importer/schema/parliament_issue.json
321
+ - lib/hdo/storting_importer/schema/parliament_period.json
322
+ - lib/hdo/storting_importer/schema/parliament_session.json
318
323
  - lib/hdo/storting_importer/schema/party.json
319
324
  - lib/hdo/storting_importer/schema/party_membership.json
320
325
  - lib/hdo/storting_importer/schema/promise.json
@@ -329,7 +334,10 @@ files:
329
334
  - spec/hdo/storting_importer/committee_membership_spec.rb
330
335
  - spec/hdo/storting_importer/committee_spec.rb
331
336
  - spec/hdo/storting_importer/district_spec.rb
337
+ - spec/hdo/storting_importer/governing_period_spec.rb
332
338
  - spec/hdo/storting_importer/parliament_issue_spec.rb
339
+ - spec/hdo/storting_importer/parliament_period_spec.rb
340
+ - spec/hdo/storting_importer/parliament_session_spec.rb
333
341
  - spec/hdo/storting_importer/party_membership_spec.rb
334
342
  - spec/hdo/storting_importer/party_spec.rb
335
343
  - spec/hdo/storting_importer/promise_spec.rb
@@ -351,12 +359,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
359
  - - ! '>='
352
360
  - !ruby/object:Gem::Version
353
361
  version: '0'
362
+ segments:
363
+ - 0
364
+ hash: 200633762499888561
354
365
  required_rubygems_version: !ruby/object:Gem::Requirement
355
366
  none: false
356
367
  requirements:
357
368
  - - ! '>='
358
369
  - !ruby/object:Gem::Version
359
370
  version: '0'
371
+ segments:
372
+ - 0
373
+ hash: 200633762499888561
360
374
  requirements: []
361
375
  rubyforge_project:
362
376
  rubygems_version: 1.8.24
@@ -371,7 +385,10 @@ test_files:
371
385
  - spec/hdo/storting_importer/committee_membership_spec.rb
372
386
  - spec/hdo/storting_importer/committee_spec.rb
373
387
  - spec/hdo/storting_importer/district_spec.rb
388
+ - spec/hdo/storting_importer/governing_period_spec.rb
374
389
  - spec/hdo/storting_importer/parliament_issue_spec.rb
390
+ - spec/hdo/storting_importer/parliament_period_spec.rb
391
+ - spec/hdo/storting_importer/parliament_session_spec.rb
375
392
  - spec/hdo/storting_importer/party_membership_spec.rb
376
393
  - spec/hdo/storting_importer/party_spec.rb
377
394
  - spec/hdo/storting_importer/promise_spec.rb
@@ -381,4 +398,3 @@ test_files:
381
398
  - spec/spec_helper.rb
382
399
  - spec/support/shared_examples_for_json_schema.rb
383
400
  - spec/support/shared_examples_for_short_inspect.rb
384
- has_rdoc: