module Infoboxer::Tree::Linkable

Module included into everything, that can be treated as link to some MediaWiki page, despite of behavior. Namely, {Wikilink} and {Template}.

Public Instance Methods

follow() click to toggle source

Extracts wiki page by this link and returns it parsed (or nil, if page not found).

About template “following” see also {Template#follow} docs.

@return {MediaWiki::Page}

**See also**:

  • {Tree::Nodes#follow} for extracting multiple links at once;

  • {MediaWiki#get} for basic information on page extraction.

# File lib/infoboxer/tree/linkable.rb, line 19
def follow
  client.get(link, interwiki: interwiki)
end
url() click to toggle source

Human-readable page URL

@return [String]

# File lib/infoboxer/tree/linkable.rb, line 26
def url
  # FIXME: fragile as hell.
  page.url.sub(%r{[^/]+$}, link.tr(' ', '_'))
end

Protected Instance Methods

client() click to toggle source
# File lib/infoboxer/tree/linkable.rb, line 40
def client
  page.client or fail('MediaWiki client not set')
end
interwiki() click to toggle source

redefined in {Wikilink}

# File lib/infoboxer/tree/linkable.rb, line 34
def interwiki; end
page() click to toggle source
# File lib/infoboxer/tree/linkable.rb, line 36
def page
  lookup_parents(MediaWiki::Page).first or fail('Not in a page from real source')
end