hdo-storting-importer 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module Hdo
|
|
8
8
|
include HasJsonSchema
|
9
9
|
include IvarEquality
|
10
10
|
|
11
|
-
attr_reader :external_id, :
|
11
|
+
attr_reader :external_id, :parties, :body, :general, :categories, :source, :page, :date
|
12
12
|
alias_method :general?, :general
|
13
13
|
alias_method :short_inspect, :inspect
|
14
14
|
|
@@ -17,7 +17,7 @@ module Hdo
|
|
17
17
|
def self.example
|
18
18
|
new(
|
19
19
|
"1",
|
20
|
-
"H",
|
20
|
+
["H"],
|
21
21
|
"Stille strengere krav til orden og oppførsel for å hindre at uro ødelegger undervisningen.",
|
22
22
|
true,
|
23
23
|
["GRUNNSKOLE"],
|
@@ -45,7 +45,7 @@ module Hdo
|
|
45
45
|
|
46
46
|
external_id = data.fetch(0).to_i.to_s
|
47
47
|
date = data.fetch(1)
|
48
|
-
|
48
|
+
parties = data.fetch(2)
|
49
49
|
body = data.fetch(3)
|
50
50
|
general = data.fetch(4).to_s.strip.downcase
|
51
51
|
categories = data.fetch(5)
|
@@ -62,8 +62,8 @@ module Hdo
|
|
62
62
|
next
|
63
63
|
end
|
64
64
|
|
65
|
-
unless
|
66
|
-
errors << "row #{external_id}:
|
65
|
+
unless parties
|
66
|
+
errors << "row #{external_id}: parties missing"
|
67
67
|
next
|
68
68
|
end
|
69
69
|
|
@@ -72,7 +72,7 @@ module Hdo
|
|
72
72
|
end
|
73
73
|
|
74
74
|
promise = new external_id,
|
75
|
-
|
75
|
+
parties.strip,
|
76
76
|
body.strip,
|
77
77
|
general.downcase == "ja",
|
78
78
|
categories,
|
@@ -91,7 +91,8 @@ module Hdo
|
|
91
91
|
}.compact
|
92
92
|
|
93
93
|
if errors.any?
|
94
|
-
|
94
|
+
puts errors
|
95
|
+
# raise "found errors:\n#{errors.join("\n")}"
|
95
96
|
end
|
96
97
|
|
97
98
|
promises
|
@@ -99,7 +100,7 @@ module Hdo
|
|
99
100
|
|
100
101
|
def self.from_hash(hash)
|
101
102
|
pr = new hash['externalId'],
|
102
|
-
hash['
|
103
|
+
hash['parties'],
|
103
104
|
hash['body'],
|
104
105
|
hash['general'],
|
105
106
|
hash['categories'],
|
@@ -110,12 +111,12 @@ module Hdo
|
|
110
111
|
pr
|
111
112
|
end
|
112
113
|
|
113
|
-
def initialize(external_id,
|
114
|
+
def initialize(external_id, parties, body, general, categories, source, page, date)
|
114
115
|
@external_id = external_id
|
115
|
-
@
|
116
|
+
@parties = clean_array(parties)
|
116
117
|
@body = strip_if_string(body)
|
117
118
|
@general = general
|
118
|
-
@categories =
|
119
|
+
@categories = clean_array(categories).map { |e| UnicodeUtils.upcase(e) }
|
119
120
|
@source = strip_if_string(source)
|
120
121
|
@page = page
|
121
122
|
@date = date
|
@@ -125,7 +126,7 @@ module Hdo
|
|
125
126
|
{
|
126
127
|
'kind' => self.class.kind,
|
127
128
|
'externalId' => @external_id,
|
128
|
-
'
|
129
|
+
'parties' => @parties,
|
129
130
|
'general' => @general,
|
130
131
|
'categories' => @categories,
|
131
132
|
'source' => @source,
|
@@ -137,12 +138,9 @@ module Hdo
|
|
137
138
|
|
138
139
|
private
|
139
140
|
|
140
|
-
def
|
141
|
+
def clean_array(categories)
|
141
142
|
categories = categories.split(",") if categories.kind_of?(String)
|
142
|
-
|
143
|
-
Array(categories).map(&:strip).
|
144
|
-
reject(&:empty?).
|
145
|
-
map { |e| UnicodeUtils.upcase(e) }
|
143
|
+
Array(categories).map(&:strip).reject(&:empty?)
|
146
144
|
end
|
147
145
|
|
148
146
|
def strip_if_string(str)
|
@@ -14,10 +14,13 @@
|
|
14
14
|
"description": "A unique identifier for this promise.",
|
15
15
|
"required": true
|
16
16
|
},
|
17
|
-
"
|
18
|
-
"type": "
|
19
|
-
"description": "
|
20
|
-
"required": true
|
17
|
+
"parties": {
|
18
|
+
"type": "array",
|
19
|
+
"description": "List of parties (i.e. 'A', 'SV', 'Sp'). Usually a single party.",
|
20
|
+
"required": true,
|
21
|
+
"items": {
|
22
|
+
"type": "string"
|
23
|
+
}
|
21
24
|
},
|
22
25
|
"general": {
|
23
26
|
"type": "boolean",
|
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.1.
|
4
|
+
version: 0.1.8
|
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-
|
12
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|