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 =
- WIKI_PASSWORD =
- NO_ID_ERROR =
<<~WIKITEXT '''#{WIKI_TEMPLATE_NAME} Error''': You must pass the <code>id</code> parameter to the <code>#{WIKI_TEMPLATE_NAME}</code> template; e.g. <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki> WIKITEXT
- MALFORMED_ID_ERROR =
<<~WIKITEXT '''#{WIKI_TEMPLATE_NAME} Error''': The <code>id</code> parameter was malformed; it should be Q followed by a number of digits, e.g. as in: <nowiki>{{#{WIKI_TEMPLATE_NAME}|id=Q14211}}</nowiki> WIKITEXT
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.
51 52 53 54 |
# File 'lib/wikidata_position_history.rb', line 51 def initialize(mediawiki_site:, page_title:) @mediawiki_site = mediawiki_site @page_title = page_title.tr('_', ' ') end |
Instance Method Details
#new_content ⇒ Object
60 61 62 63 64 65 |
# File 'lib/wikidata_position_history.rb', line 60 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
56 57 58 |
# File 'lib/wikidata_position_history.rb', line 56 def run! section.replace_output(*new_content) end |