Class: WikidataPositionHistory::PageRewriter
- Inherits:
-
Object
- Object
- WikidataPositionHistory::PageRewriter
- Defined in:
- lib/wikidata_position_history.rb
Overview
Rewrites a Wiki page
Constant Summary collapse
- WIKI_TEMPLATE_NAME =
'PositionHolderHistory'- WIKI_USERNAME =
ENV['WIKI_USERNAME']
- WIKI_PASSWORD =
ENV['WIKI_PASSWORD']
- NO_ID_ERROR =
"'''\#{WIKI_TEMPLATE_NAME} Error''': You must pass the <code>id</code>\nparameter to the <code>\#{WIKI_TEMPLATE_NAME}</code> template; e.g.\n<nowiki>{{\#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>\n"- MALFORMED_ID_ERROR =
"'''\#{WIKI_TEMPLATE_NAME} Error''': The <code>id</code> parameter was\nmalformed; it should be Q followed by a number of digits, e.g. as in:\n\n<nowiki>{{\#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki>\n"
Instance Method Summary collapse
-
#initialize(mediawiki_site:, page_title:) ⇒ PageRewriter
constructor
A new instance of PageRewriter.
- #new_content ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(mediawiki_site:, page_title:) ⇒ PageRewriter
Returns a new instance of PageRewriter.
39 40 41 42 |
# File 'lib/wikidata_position_history.rb', line 39 def initialize(mediawiki_site:, page_title:) @mediawiki_site = mediawiki_site @page_title = page_title.tr('_', ' ') end |
Instance Method Details
#new_content ⇒ Object
48 49 50 51 52 53 |
# File 'lib/wikidata_position_history.rb', line 48 def new_content return [NO_ID_ERROR, 'The id parameter was missing'] if position_id.empty? return [MALFORMED_ID_ERROR, 'The id parameter was malformed'] unless position_id[/^Q\d+$/] [WikidataPositionHistory::Report.new(position_id).wikitext, "Successfully updated holders of #{position_id}"] end |
#run! ⇒ Object
44 45 46 |
# File 'lib/wikidata_position_history.rb', line 44 def run! section.replace_output(*new_content) end |