Class: Pumi::Bot::Wikipedia::DistrictsInCambodiaArticle

Inherits:
Article
  • Object
show all
Defined in:
lib/pumi/bot/wikipedia/districts_in_cambodia_article.rb

Defined Under Namespace

Classes: Misspelling

Constant Summary collapse

PAGE_TITLE =
"List_of_districts,_municipalities_and_sections_in_Cambodia".freeze
INTRO_TEXT =
"This is a list of [[Cambodia]]'s %<districts_count>s districts ({{lang|km|ស្រុក}} ''srok''), %<municipalities_count>s district-level municipalities ({{lang|km|ក្រុង}} ''krong'') and %<sections_count>s sections ({{lang|km|ខណ្ឌ}} ''khan'') organized by each [[Provinces of Cambodia|province]] and an [[Provinces of Cambodia|autonomous municipality]] ([[Phnom Penh]]).".freeze
DISTRICTS_TEMPLATE =
File.read("#{__dir__}/templates/district_list.wikitext.erb")
MISSPELLINGS =
[
  Misspelling.new(
    incorrect_text: "Phnom Penh (autonomous municipality)",
    correct_text: "Phnom Penh"
  )
].freeze

Instance Attribute Summary

Attributes inherited from Article

#client

Instance Method Summary collapse

Methods inherited from Article

#initialize

Constructor Details

This class inherits a constructor from Pumi::Bot::Wikipedia::Article

Instance Method Details

#publishObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pumi/bot/wikipedia/districts_in_cambodia_article.rb', line 22

def publish
  page = client.get_page(title: PAGE_TITLE)
  source = page.fetch(:source).dup

  replace_intro(source:, replacement: generate_intro)
  replace_number_of_districts(source:, replacement: District.all.size)

  Pumi::Province.all.each do |province|
    section = find_section_by_title(source:, title: province.name_en)
    new_section = generate_districts_section(province:)
    source.sub!(section[1], new_section)
  end

  client.update_page(title: PAGE_TITLE, source:, comment: "Update page")
end