Module: Infoboxer

Defined in:
lib/infoboxer.rb,
lib/infoboxer/tree.rb,
lib/infoboxer/parser.rb,
lib/infoboxer/version.rb,
lib/infoboxer/tree/ref.rb,
lib/infoboxer/templates.rb,
lib/infoboxer/tree/html.rb,
lib/infoboxer/tree/list.rb,
lib/infoboxer/tree/node.rb,
lib/infoboxer/tree/text.rb,
lib/infoboxer/media_wiki.rb,
lib/infoboxer/navigation.rb,
lib/infoboxer/tree/image.rb,
lib/infoboxer/tree/nodes.rb,
lib/infoboxer/tree/table.rb,
lib/infoboxer/parser/html.rb,
lib/infoboxer/parser/util.rb,
lib/infoboxer/tree/inline.rb,
lib/infoboxer/parser/image.rb,
lib/infoboxer/parser/table.rb,
lib/infoboxer/parser/inline.rb,
lib/infoboxer/templates/set.rb,
lib/infoboxer/tree/compound.rb,
lib/infoboxer/tree/document.rb,
lib/infoboxer/tree/linkable.rb,
lib/infoboxer/tree/template.rb,
lib/infoboxer/tree/wikilink.rb,
lib/infoboxer/parser/context.rb,
lib/infoboxer/templates/base.rb,
lib/infoboxer/media_wiki/page.rb,
lib/infoboxer/parser/template.rb,
lib/infoboxer/tree/paragraphs.rb,
lib/infoboxer/media_wiki/traits.rb,
lib/infoboxer/navigation/lookup.rb,
lib/infoboxer/parser/paragraphs.rb,
lib/infoboxer/navigation/sections.rb,
lib/infoboxer/navigation/selector.rb,
lib/infoboxer/navigation/shortcuts.rb,
lib/infoboxer/definitions/en.wikipedia.org.rb

Overview

Main client module for entire infoboxer functionality. If you're lucky, there's no other classes/modules you need to instantiate or call directly. You just do:

Infoboxer.wp.get('List of radio telescopes')
# or 
Infoboxer.wikiquote.get('Vonnegut')

...and have fully navigable Wiki information.

Please read wiki for extensive showcases and usage recommendations.

Here's main components list, which also can serve as a TOC for Infoboxer's functionality (we suggest to read their docs in this order):

  • Tree -- nodes, of which Wikipedia AST is consisting; you'll be interested in basic Tree::Node functionality, as well as node classes list (which is useful for navigation);
  • Navigation -- how to navigate the tree you have, basic way (children, parents, siblings) and hi-level shortcuts way (like all unnumbered list items in second level-3 section);
  • Templates -- the most advanced data extraction from wikipedia definitely needs your undestanding of this (rather complicated) topic.

You also may be interested in (though may be never need to use them directly):

Defined Under Namespace

Modules: Navigation, Templates, Tree Classes: MediaWiki, Parser

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.commons(options = {}) ⇒ MediaWiki

Shortcut for creating WikiMedia Commons client.

Parameters:

  • options (see #wiki for list of options) (defaults to: {})

Returns:



# File 'lib/infoboxer.rb', line 84

.species(options = {}) ⇒ MediaWiki

Shortcut for creating Wikispecies client.

Parameters:

  • options (see #wiki for list of options) (defaults to: {})

Returns:



# File 'lib/infoboxer.rb', line 120

.user_agent=(ua) ⇒ Object

Sets user agent string globally. Default user agent is Infoboxer::MediaWiki::UA.

User agent can also be rewriten as an option to wiki method (and its shortcuts like wikipedia), or by using Infoboxer::MediaWiki#initialize explicitly.



180
181
182
# File 'lib/infoboxer.rb', line 180

def user_agent=(ua)
  MediaWiki.user_agent = ua
end

.wiki(api_url, options = {}) ⇒ MediaWiki

Default method for creating MediaWiki API client.

Parameters:

  • api_url

    should be URL of api.php for your MediaWiki

  • options (defaults to: {})

    list of options. The only recognized option for now, though, is

    • :user_agent (also aliased as :ua) -- custom User-Agent header.

Returns:

  • (MediaWiki)

    an instance of API client, which you can further use like this:

    Infoboxer.wiki('some_url').get('Some page title')
    


73
74
75
# File 'lib/infoboxer.rb', line 73

def wiki(api_url, options = {})
  MediaWiki.new(api_url, options || {})
end

.wikia(*domains) ⇒ MediaWiki .wikia(*domains, options) ⇒ MediaWiki

Performs request to wikia.com wikis.

Overloads:

  • .wikia(*domains) ⇒ MediaWiki

    Parameters:

    • *domains

      list of domains to merge, like this:

      Infoboxer.wikia('tardis') # looks at tardis.wikia.com
      Infoboxer.wikia('tardis', 'ru') # looks in Russian version, ru.tardis.wikia.com
      

      If you are surprised by "reversing" list of subdomains, think of it as of chain of refinements (looking in "tardis" wiki, its "ru" version, specifically).

  • .wikia(*domains, options) ⇒ MediaWiki

    Parameters:

    • *domains

      same as above

    • options

      just last of params, if it is hash (see wiki for list of options)

Returns:



168
169
170
171
# File 'lib/infoboxer.rb', line 168

def wikia(*domains)
  options = domains.last.is_a?(Hash) ? domains.pop : {}
  wiki(WIKIA_API_URL % domains.reverse.join('.'), options)
end

.wikibooks(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikibooks client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 90

.wikinews(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikinews client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 115

.wikipedia(lang = 'en', options = {}) ⇒ MediaWiki Also known as: wp

Shortcut for creating Wikipedia client.

Parameters:

  • lang (defaults to: 'en')

    two-character code for language version

  • options (see #wiki for list of options) (defaults to: {})

Returns:



# File 'lib/infoboxer.rb', line 77

.wikiquote(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikiquote client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 95

.wikisource(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikisource client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 105

.wikiversity(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikiversity client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 100

.wikivoyage(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wikivoyage client. See wikipedia for params explanation.

Returns:



# File 'lib/infoboxer.rb', line 110

.wiktionary(lang = 'en', options = {}) ⇒ MediaWiki

Shortcut for creating Wiktionary client. See wikipedia for params explanation.

Returns:



131
132
133
134
135
136
137
138
139
# File 'lib/infoboxer.rb', line 131

WIKIMEDIA_PROJECTS.each do |name, domain|
  define_method name do |lang = 'en', options = {}|
    if lang.is_a?(Hash)
      lang, options = 'en', lang
    end

    wiki("http://#{lang}.#{domain}/w/api.php", options)
  end
end