Class: Infoboxer::Tree::Wikilink

Inherits:
Link show all
Includes:
Linkable
Defined in:
lib/infoboxer/tree/wikilink.rb

Overview

Internal MediaWiki link class.

See Wikipedia docs for extensive explanation of Wikilink concept.

Note, that Wikilink is Linkable, so you can #follow it to obtain linked pages.

Instance Attribute Summary collapse

Attributes inherited from Link

#link

Attributes inherited from Compound

#children

Attributes inherited from Node

#params, #parent

Instance Method Summary collapse

Methods included from Linkable

#follow, #url

Methods inherited from Compound

#index_of, #text, #to_tree

Methods inherited from Node

#==, #children, coder, def_readers, #first?, #index, #inspect, #next_siblings, #prev_siblings, #siblings, #text, #text_, #to_s, #to_tree

Methods included from Navigation::Wikipath

#wikipath

Methods included from Navigation::Sections::Node

#in_sections

Methods included from Navigation::Shortcuts::Node

#bold?, #categories, #external_links, #heading?, #headings, #images, #infobox, #infoboxes, #italic?, #lists, #paragraphs, #tables, #templates, #wikilinks

Methods included from Navigation::Lookup::Node

#_lookup, #_lookup_children, #_lookup_next_siblings, #_lookup_parents, #_lookup_prev_sibling, #_lookup_prev_siblings, #_lookup_siblings, #_matches?, #lookup, #lookup_children, #lookup_next_siblings, #lookup_parents, #lookup_prev_sibling, #lookup_prev_siblings, #lookup_siblings, #matches?, #parent?

Constructor Details

#initialize(link, label = nil, namespace: nil, interwiki: nil) ⇒ Wikilink

Returns a new instance of Wikilink.



15
16
17
18
19
20
# File 'lib/infoboxer/tree/wikilink.rb', line 15

def initialize(link, label = nil, namespace: nil, interwiki: nil)
  super(link, label, namespace: namespace, interwiki: interwiki)
  @namespace = namespace || ''
  @interwiki = interwiki
  parse_name!
end

Instance Attribute Details

#anchorObject (readonly)

Anchor part of hyperlink, like History for [Argentina#History]



37
38
39
# File 'lib/infoboxer/tree/wikilink.rb', line 37

def anchor
  @anchor
end

#interwikiObject (readonly)

Interwiki identifier. For example, [[wikt:Argentina]] will have "Argentina" as its #name and "wikt" (wiktionary) as an interwiki. TODO: how to use it.

See Wikipedia docs for details.



30
31
32
# File 'lib/infoboxer/tree/wikilink.rb', line 30

def interwiki
  @interwiki
end

#nameObject (readonly)

"Clean" wikilink name, for ex., Cities for [Category:Cities]



23
24
25
# File 'lib/infoboxer/tree/wikilink.rb', line 23

def name
  @name
end

#namespaceObject (readonly)

Wikilink namespace, Category for [Category:Cities], empty string (not nil!) for just [Cities]



34
35
36
# File 'lib/infoboxer/tree/wikilink.rb', line 34

def namespace
  @namespace
end

#refinementObject (readonly)

Refinement part of link name.

See #topic for explanation.



52
53
54
# File 'lib/infoboxer/tree/wikilink.rb', line 52

def refinement
  @refinement
end

#topicObject (readonly)

Topic part of link name.

There's so-called "Pipe trick" in wikilink markup, which defines that [Phoenix, Arizona] link has main part ("Phoenix") and refinement part ("Arizona"). So, we are splitting it here in topic and #refinement. The same way, [Pipe (programming)] has topic == 'Pipe' and refinement == 'programming'



47
48
49
# File 'lib/infoboxer/tree/wikilink.rb', line 47

def topic
  @topic
end