module Infoboxer
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:
“`ruby Infoboxer.wp.get('List of radio telescopes') # or Infoboxer.wikiquote.get('Vonnegut') “` …and have fully navigable Wiki information.
Please read [wiki](github.com/molybdenum-99/infoboxer/wiki) for extensive [showcases](github.com/molybdenum-99/infoboxer/wiki/Showcase) 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):
-
{MediaWiki} client class;
-
{Parser} – which, you know, parses.
NB `Infoboxer` module can also be included in other classes, like this:
“`ruby class MyDataGrabber
include Infoboxer def initialize wikipedia.get('Argentina') end
end “`
rubocop:disable Layout/EmptyLinesAroundArguments
Constants
- ALLOW_BETWEEN
- MAJOR
- MINOR
- PATCH
- PRE
- VERSION
- WIKIA_API_URL
@private
- WIKIMEDIA_COMMONS
- WIKIMEDIA_PROJECTS
Public Class Methods
Sets user agent string globally. Default user agent is {MediaWiki::UA}.
User agent can also be rewriten as an option to {wiki} method (and its shortcuts like {wikipedia}), or by using {MediaWiki#initialize} explicitly.
# File lib/infoboxer.rb, line 241 def self.user_agent=(ua) MediaWiki.user_agent = ua end
Public Instance Methods
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 246 def between ALLOW_BETWEEN.include?(fetch('2').text) ? fetch('2').text : nil end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 135 def children fetch('1') end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 286 def date fetch_date('1', '2', '3') end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 268 def from fetch_date('1', '2', '3') end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 187 def infobox? true end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 209 def lat case model when :decimal '%s°%s′%s' % fetch('1', '2').map(&:text) when :decimal_sign fetch('1').text when :min '%s°%s′%s' % fetch('1', '2', '3').map(&:text) when :sec '%s°%s′%s″%s' % fetch('1', '2', '3', '4').map(&:text) end end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 222 def lng case model when :decimal, :decimal_sign fetch('1').text when :min '%s°%s′%s' % fetch('1', '2', '3').map(&:text) when :sec '%s°%s′%s″%s' % fetch('1', '2', '3', '4').map(&:text) end end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 254 def measure_from between ? fetch('4').text : fetch('2').text end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 258 def measure_to between ? fetch('5').text : fetch('3').text end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 193 def model @model ||= begin npos = lookup_children(text: /^N|S$/).first.index rescue nil # rubocop:disable Style/RescueModifier case npos when 1 :decimal when 2 :min when 3 :sec else :decimal_sign end end end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 181 def stub? true end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 262 def text [value1, between, value2, measure_from].compact.join(' ') end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 272 def to fetch_date('4', '5', '6') || Date.today end
Returns URL of API entry-point for a well-known Wiki-project (wikipedia, wikivoyage etc.) by project's name.
@param symbol [Symbol] One of {WIKIMEDIA_PROJECTS} or {WIKIMEDIA_COMMONS} keys. @param lang [String, Symbol] Language of the project, if applicable. @return [String]
# File lib/infoboxer.rb, line 190 def url_for(symbol, lang = 'en') if (domain = WIKIMEDIA_PROJECTS[symbol]) "https://#{lang}.#{domain}/w/api.php" elsif (domain = WIKIMEDIA_COMMONS[symbol]) "https://#{domain}/w/api.php" end end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 276 def value (to - from).to_i / 365 # FIXME: obviously end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 235 def value1 fetch('1').text end
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 250 def value2 between ? fetch('3').text : nil end
Includeable version of {Infoboxer.wiki}
# File lib/infoboxer.rb, line 73 def wiki(api_url, **options) wikis[api_url] ||= MediaWiki.new(api_url, **options) end
Includeable version of {Infoboxer.wikia}
# File lib/infoboxer.rb, line 229 def wikia(*domains) options = domains.last.is_a?(Hash) ? domains.pop : {} wiki(WIKIA_API_URL % domains.reverse.join('.'), **options) end
# File lib/infoboxer.rb, line 68 def wikis @wikis ||= {} end