wikidata_position_history 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ef4815c74d73d50bd3d74a70af9d9b47177d5f3c00e35748892cad201150bed
4
- data.tar.gz: fdd1e8b5fa7fe220da78daabdcdc016e8ee729c57648103bbc384860e2ef0ce6
3
+ metadata.gz: d6133f77b6d65f7decf2dcac481ff36a661a136fb79aff442677669801248437
4
+ data.tar.gz: dccd3b0a0ed29d89c945756c9efa30e8c02f1c912b4402bec1a45a1c45d81e88
5
5
  SHA512:
6
- metadata.gz: fe138774ce37cf9258c7f11bfc3bc95cbaafa3811507a2b963d006d1e5982e9257ce754ea46fe47fe7e3eabb95520ae534549badcc6a7c8335ee3ff4368cef82
7
- data.tar.gz: 2e266bd52f9bef2e8736bcf566c1ec5e4b7ad10a90f13d4a31f6613411797ff01e4a528263db3b15cce573de10c4c41eb36ea46838f7d16c30748a3a58585564
6
+ metadata.gz: 0112ca4aae8b9631d86bbf1c2cca5120808e9eb1bb207008e8ba8d221ec0c0c2d16e5f22ec0c59fe9454839c04fcd32bd71f67d1e1793e0d8c053b9d2f1d1471
7
+ data.tar.gz: 8fd03fc79a37459686524927ba536ab770c22ac4c8d948fde53be1eafba155a3a0f2b072cd8ab8142867e0f57a8138ac62c1535d54bf5330e987bbfc7a2a553e
@@ -1,3 +1,7 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  Exclude:
3
7
  - 'Vagrantfile'
@@ -29,6 +33,13 @@ Lint/AssignmentInCondition:
29
33
  Naming/ClassAndModuleCamelCase:
30
34
  Enabled: false
31
35
 
36
+ RSpec/DescribedClass:
37
+ Enabled: false
38
+
39
+ # TODO: remove this?
40
+ RSpec/MultipleExpectations:
41
+ Max: 2
42
+
32
43
  Style/CollectionMethods:
33
44
  Enabled: true
34
45
 
@@ -52,3 +63,6 @@ Style/TrailingCommaInHashLiteral:
52
63
 
53
64
  Style/TrailingCommaInArrayLiteral:
54
65
  EnforcedStyleForMultiline: no_comma
66
+
67
+ Layout/ClassStructure:
68
+ Enabled: true
@@ -1,5 +1,48 @@
1
1
  # Changelog
2
2
 
3
+ # [1.6.0] 2020-09-07
4
+
5
+ ## Enhancements
6
+
7
+ * If a position has an inception date and/or abolition date, those will
8
+ now also be displayed. (If a position has more than one of either of
9
+ those — which really shouldn't happen, but sometimes does — then the
10
+ behaviour may not be particularly sensible. Later evolutions of this
11
+ feature will hopefully handle that better.)
12
+
13
+ ## Fixes
14
+
15
+ * Previously, any warnings would be displayed at the bottom of the page,
16
+ which was fine if this table was the only thing on the page, but would
17
+ be slightly odd if there was other discussion after it. Now the
18
+ footnotes are explicitly displayed immediately after the table.
19
+
20
+ # [1.5.0] 2020-09-06
21
+
22
+ ## Enhancements
23
+
24
+ * When showing the results for a position from long long ago (such as
25
+ the High Kings of Ireland), display the dates as "862 – 879" not as
26
+ "862 – 879"
27
+ * If we only know that someone took (or left) office sometime in a given
28
+ decade (i.e. at date precision 8), display that as (say) "1930s"
29
+
30
+ ## Fixes
31
+
32
+ * No longer blows up when a P39 has a start date, but no end date
33
+
34
+ # [1.4.2] 2020-09-05
35
+
36
+ ## Fixes
37
+
38
+ * Bring back the warnings when start or end dates are missing.
39
+
40
+ # [1.4.1] 2020-09-04
41
+
42
+ ## Fixes
43
+
44
+ * Work around template deployment issue.
45
+
3
46
  # [1.4.0] 2020-09-04
4
47
 
5
48
  ## Enhancements
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rubocop/rake_task'
8
8
  Rake::TestTask.new(:test) do |t|
9
9
  t.libs << 'test'
10
10
  t.libs << 'lib'
11
- t.test_files = FileList['test/**/*_test.rb']
11
+ t.test_files = FileList['test/**/*_{spec,test}.rb']
12
12
  end
13
13
 
14
14
  desc 'Run rubocop'
@@ -54,6 +54,8 @@ module QueryService
54
54
  class WikidataDate
55
55
  include Comparable
56
56
 
57
+ DATELEN = { '11' => 10, '10' => 7, '9' => 4, '8' => 4 }.freeze
58
+
57
59
  def initialize(str, precision)
58
60
  @str = str
59
61
  @raw_precision = precision.to_s
@@ -66,12 +68,7 @@ module QueryService
66
68
  end
67
69
 
68
70
  def to_s
69
- return str if precision == '11'
70
- return str[0..6] if precision == '10'
71
- return str[0..3] if precision == '9'
72
-
73
- warn "Cannot handle precision #{precision} for #{str}"
74
- str
71
+ precisioned_string.delete_prefix('0')
75
72
  end
76
73
 
77
74
  def empty?
@@ -99,5 +96,18 @@ module QueryService
99
96
  def parts
100
97
  to_s.split('-')
101
98
  end
99
+
100
+ def truncated_string
101
+ return str[0...DATELEN[precision]] if DATELEN.key?(precision)
102
+
103
+ warn "Cannot handle precision #{precision} for #{str}"
104
+ str
105
+ end
106
+
107
+ def precisioned_string
108
+ return "#{truncated_string}s" if precision == '8'
109
+
110
+ truncated_string
111
+ end
102
112
  end
103
113
  end
@@ -63,10 +63,14 @@ module WikidataPositionHistory
63
63
  end
64
64
 
65
65
  def start_date
66
+ return if start_date_raw.empty?
67
+
66
68
  QueryService::WikidataDate.new(start_date_raw, start_date_precision)
67
69
  end
68
70
 
69
71
  def end_date
72
+ return if end_date_raw.empty?
73
+
70
74
  QueryService::WikidataDate.new(end_date_raw, end_date_precision)
71
75
  end
72
76
 
@@ -28,10 +28,14 @@ module WikidataPositionHistory
28
28
  end
29
29
 
30
30
  def inception_date
31
+ return if inception_date_raw.empty?
32
+
31
33
  QueryService::WikidataDate.new(inception_date_raw, inception_date_precision)
32
34
  end
33
35
 
34
36
  def abolition_date
37
+ return if abolition_date_raw.empty?
38
+
35
39
  QueryService::WikidataDate.new(abolition_date_raw, abolition_date_precision)
36
40
  end
37
41
 
@@ -6,6 +6,7 @@ require 'sparql/position_data'
6
6
  require 'sparql/bio_data'
7
7
  require 'sparql/mandates'
8
8
  require 'wikidata_position_history/checks'
9
+ require 'wikidata_position_history/template'
9
10
  require 'wikidata_position_history/report'
10
11
  require 'wikidata_position_history/version'
11
12
 
@@ -21,6 +22,19 @@ module WikidataPositionHistory
21
22
  WIKI_USERNAME = ENV['WIKI_USERNAME']
22
23
  WIKI_PASSWORD = ENV['WIKI_PASSWORD']
23
24
 
25
+ NO_ID_ERROR = <<~WIKITEXT
26
+ '''#{WIKI_TEMPLATE_NAME} Error''': You must pass the <code>id</code>
27
+ parameter to the <code>#{WIKI_TEMPLATE_NAME}</code> template; e.g.
28
+ <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>
29
+ WIKITEXT
30
+
31
+ MALFORMED_ID_ERROR = <<~WIKITEXT
32
+ '''#{WIKI_TEMPLATE_NAME} Error''': The <code>id</code> parameter was
33
+ malformed; it should be Q followed by a number of digits, e.g. as in:
34
+
35
+ <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>
36
+ WIKITEXT
37
+
24
38
  def initialize(mediawiki_site:, page_title:)
25
39
  @mediawiki_site = mediawiki_site
26
40
  @page_title = page_title.tr('_', ' ')
@@ -32,7 +46,7 @@ module WikidataPositionHistory
32
46
 
33
47
  def new_content
34
48
  return [NO_ID_ERROR, 'The id parameter was missing'] if position_id.empty?
35
- return [MALFORMED_ID_ERROR, 'The id parameter was malformed'] unless position_id =~ /^Q\d+$/
49
+ return [MALFORMED_ID_ERROR, 'The id parameter was malformed'] unless position_id[/^Q\d+$/]
36
50
 
37
51
  [WikidataPositionHistory::Report.new(position_id).wikitext, "Successfully updated holders of #{position_id}"]
38
52
  end
@@ -41,19 +55,6 @@ module WikidataPositionHistory
41
55
 
42
56
  attr_reader :mediawiki_site, :page_title
43
57
 
44
- NO_ID_ERROR = <<~EOERROR
45
- '''#{WIKI_TEMPLATE_NAME} Error''': You must pass the <code>id</code>
46
- parameter to the <code>#{WIKI_TEMPLATE_NAME}</code> template; e.g.
47
- <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>
48
- EOERROR
49
-
50
- MALFORMED_ID_ERROR = <<~EOERROR
51
- '''#{WIKI_TEMPLATE_NAME} Error''': The <code>id</code> parameter was
52
- malformed; it should be Q followed by a number of digits, e.g. as in:
53
-
54
- <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>
55
- EOERROR
56
-
57
58
  def position_id
58
59
  return id_param unless id_param.empty?
59
60
 
@@ -124,10 +124,10 @@ module WikidataPositionHistory
124
124
  def problem?
125
125
  return false unless later
126
126
 
127
- ends = current.end_date
128
- return false if ends.empty?
127
+ next_starts = later.start_date or return false
128
+ ends = current.end_date or return false
129
129
 
130
- ends > later.start_date
130
+ ends > next_starts
131
131
  rescue ArgumentError
132
132
  true
133
133
  end
@@ -3,6 +3,8 @@
3
3
  module WikidataPositionHistory
4
4
  # Date for a single mandate row, to be passed to the report template
5
5
  class MandateData
6
+ CHECKS = [Check::MissingFields, Check::WrongPredecessor, Check::WrongSuccessor, Check::Overlap].freeze
7
+
6
8
  def initialize(later, current, earlier)
7
9
  @later = later
8
10
  @current = current
@@ -20,8 +22,7 @@ module WikidataPositionHistory
20
22
 
21
23
  def dates
22
24
  dates = [current.start_date, current.end_date]
23
- # compact doesn't work here, even if we add #nil? to WikidataDate
24
- return '' if dates.reject(&:empty?).empty?
25
+ return '' if dates.compact.empty?
25
26
 
26
27
  dates.join(' – ')
27
28
  end
@@ -36,43 +37,17 @@ module WikidataPositionHistory
36
37
 
37
38
  private
38
39
 
39
- CHECKS = [Check::MissingFields, Check::WrongPredecessor, Check::WrongSuccessor, Check::Overlap].freeze
40
-
41
40
  attr_reader :later, :current, :earlier
42
41
  end
43
42
 
44
- # Interface to the ERB Template for the output
45
- class ReportTemplate
46
- def initialize(file, data)
47
- @file = file
48
- @data = data
49
- end
50
-
51
- def output
52
- template.result_with_hash(data)
53
- end
54
-
55
- private
56
-
57
- def template_path
58
- Pathname.new(file)
59
- end
60
-
61
- def template
62
- @template ||= ERB.new(template_path.read)
63
- end
64
-
65
- attr_reader :file, :data
66
- end
67
-
68
43
  # The entire wikitext generated for this report
69
44
  class Report
70
- def initialize(position_id, template_file = 'report.erb')
45
+ def initialize(position_id, template_class = ReportTemplate)
71
46
  @position_id = position_id
72
- @template_file = template_file
47
+ @template_class = template_class
73
48
  end
74
49
 
75
- attr_reader :position_id, :template_file
50
+ attr_reader :position_id, :template_class
76
51
 
77
52
  def wikitext
78
53
  return no_items_output if mandates.empty?
@@ -95,6 +70,14 @@ module WikidataPositionHistory
95
70
  [header, wikitext].join("\n")
96
71
  end
97
72
 
73
+ def template_params
74
+ {
75
+ metadata: metadata,
76
+ table_rows: table_rows,
77
+ sparql_url: sparql.wdqs_url,
78
+ }
79
+ end
80
+
98
81
  private
99
82
 
100
83
  def metadata
@@ -128,14 +111,7 @@ module WikidataPositionHistory
128
111
  end
129
112
 
130
113
  def output
131
- ReportTemplate.new(template_file, template_params).output
132
- end
133
-
134
- def template_params
135
- {
136
- table_rows: table_rows,
137
- sparql_url: sparql.wdqs_url,
138
- }
114
+ template_class.new(template_params).output
139
115
  end
140
116
 
141
117
  def table_rows
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataPositionHistory
4
+ # Interface to the ERB Template for the output
5
+ class ReportTemplate
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def output
11
+ template.result_with_hash(data)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :data
17
+
18
+ def template
19
+ @template ||= ERB.new(template_text, nil, '-')
20
+ end
21
+
22
+ def template_text
23
+ <<~ERB
24
+ {| class="wikitable" style="text-align: center; border: none;"
25
+ <% if metadata.abolition_date -%>
26
+ |-
27
+ | colspan="3" style="padding:0.5em 2em; border: none; background: #fff; font-size: 1.25em; text-align: right;" | '''Position abolished''': <%= metadata.abolition_date %>
28
+ | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" |
29
+ <% end -%>
30
+ <% table_rows.map(&:values).each do |mandate, bio| -%>
31
+ |-
32
+ | style="padding:0.5em 2em" | <%= mandate.ordinal_string %>
33
+ | style="padding:0.5em 2em" | <%= bio.map(&:image_link).first %>
34
+ | style="padding:0.5em 2em" | <span style="font-size: <%= mandate.acting? ? '1.25em; font-style: italic;' : '1.5em' %>; display: block;"><%= mandate.person %></span> <%= mandate.dates %>
35
+ | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" | \
36
+ <% mandate.warnings.each do |warning| -%>
37
+ <span style="display: block">[[File:Pictogram voting comment.svg|15px|link=]]&nbsp;<span style="color: #d33; font-weight: bold; vertical-align: middle;"><%= warning.headline %></span>&nbsp;<ref><%= warning.explanation %></ref></span>\
38
+ <% end %>
39
+ <% end -%>
40
+ <% if metadata.inception_date -%>
41
+ |-
42
+ | colspan="3" style="padding:0.5em 2em; border: none; background: #fff; font-size: 1.25em; text-align: right;" | '''Position created''': <%= metadata.inception_date %>
43
+ | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" |
44
+ <% end -%>
45
+ |}
46
+
47
+ <div style="margin-bottom:5px; border-bottom:3px solid #2f74d0; font-size:8pt">
48
+ <div style="float:right">[<%= sparql_url %> WDQS]</div>
49
+ </div>
50
+ {{reflist}}
51
+ ERB
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WikidataPositionHistory
4
- VERSION = '1.4.0'
4
+ VERSION = '1.6.0'
5
5
  end
@@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ['Tony Bowden', 'Mark Longair']
12
12
  spec.email = ['tony@tmtm.com']
13
13
 
14
- spec.summary = 'Generates a wikitext history of a holders of a position in Wikidata'
15
- spec.homepage = 'https://github.com/everypolitician/wikidata-position-history/'
14
+ spec.summary = 'Generates a table of historic holders of a Wikidata position'
15
+ spec.homepage = 'https://github.com/tmtmtmtm/wikidata-position-history/'
16
16
  spec.license = 'MIT'
17
17
 
18
18
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_runtime_dependency 'mediawiki-replaceable-content', '0.2.1'
27
+ spec.add_runtime_dependency 'mediawiki-replaceable-content', '0.2.2'
28
28
  spec.add_runtime_dependency 'rest-client', '~> 2.0'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 2.1'
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rake', '~> 13.0'
34
34
  spec.add_development_dependency 'reek', '~> 6.0'
35
35
  spec.add_development_dependency 'rubocop', '~> 0.89'
36
+ spec.add_development_dependency 'rubocop-performance', '~> 1.8.0'
37
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.43.2'
36
38
  spec.add_development_dependency 'warning', '~> 1.1'
37
- spec.add_development_dependency 'webmock', '~> 3.0.0'
39
+ spec.add_development_dependency 'webmock', '~> 3.8.3'
38
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikidata_position_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Bowden
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-09-04 00:00:00.000000000 Z
12
+ date: 2020-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mediawiki-replaceable-content
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.2.1
20
+ version: 0.2.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.2.1
27
+ version: 0.2.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rest-client
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,34 @@ dependencies:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0.89'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop-performance
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 1.8.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 1.8.0
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop-rspec
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: 1.43.2
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: 1.43.2
126
154
  - !ruby/object:Gem::Dependency
127
155
  name: warning
128
156
  requirement: !ruby/object:Gem::Requirement
@@ -143,14 +171,14 @@ dependencies:
143
171
  requirements:
144
172
  - - "~>"
145
173
  - !ruby/object:Gem::Version
146
- version: 3.0.0
174
+ version: 3.8.3
147
175
  type: :development
148
176
  prerelease: false
149
177
  version_requirements: !ruby/object:Gem::Requirement
150
178
  requirements:
151
179
  - - "~>"
152
180
  - !ruby/object:Gem::Version
153
- version: 3.0.0
181
+ version: 3.8.3
154
182
  description:
155
183
  email:
156
184
  - tony@tmtm.com
@@ -183,10 +211,10 @@ files:
183
211
  - lib/wikidata_position_history.rb
184
212
  - lib/wikidata_position_history/checks.rb
185
213
  - lib/wikidata_position_history/report.rb
214
+ - lib/wikidata_position_history/template.rb
186
215
  - lib/wikidata_position_history/version.rb
187
- - report.erb
188
216
  - wikidata_position_history.gemspec
189
- homepage: https://github.com/everypolitician/wikidata-position-history/
217
+ homepage: https://github.com/tmtmtmtm/wikidata-position-history/
190
218
  licenses:
191
219
  - MIT
192
220
  metadata:
@@ -210,5 +238,5 @@ rubyforge_project:
210
238
  rubygems_version: 2.7.6.2
211
239
  signing_key:
212
240
  specification_version: 4
213
- summary: Generates a wikitext history of a holders of a position in Wikidata
241
+ summary: Generates a table of historic holders of a Wikidata position
214
242
  test_files: []
data/report.erb DELETED
@@ -1,11 +0,0 @@
1
- {| class="wikitable" style="text-align: center; border: none;"
2
- <% table_rows.map(&:values).each do |mandate, bio| %>|-
3
- | style="padding:0.5em 2em" | <%= mandate.ordinal_string %>
4
- | style="padding:0.5em 2em" | <%= bio.map(&:image_link).first %>
5
- | style="padding:0.5em 2em" | <span style="font-size: <%= mandate.acting? ? '1.25em; font-style: italic;' : '1.5em' %>; display: block;"><%= mandate.person %></span> <%= mandate.dates %>
6
- | style="padding:0.5em 2em 0.5em 1em; border: none; background: #fff; text-align: left;" | <% mandate.warnings.each do |warning| %><span style="display: block">[[File:Pictogram voting comment.svg|15px|link=]]&nbsp;<span style="color: #d33; font-weight: bold; vertical-align: middle;"><%= warning.headline %></span>&nbsp;<ref><%= warning.explanation %></ref></span><% end %>
7
- <% end %>|}
8
-
9
- <div style="margin-bottom:5px; border-bottom:3px solid #2f74d0; font-size:8pt">
10
- <div style="float:right">[<%= sparql_url %> WDQS]</div>
11
- </div>