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):

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

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

user_agent=(ua) click to toggle source

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

between() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 246
def between
  ALLOW_BETWEEN.include?(fetch('2').text) ? fetch('2').text : nil
end
children() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 135
def children
  fetch('1')
end
date() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 286
def date
  fetch_date('1', '2', '3')
end
from() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 268
def from
  fetch_date('1', '2', '3')
end
infobox?() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 187
def infobox?
  true
end
lat() click to toggle source
# 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
lng() click to toggle source
# 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
measure_from() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 254
def measure_from
  between ? fetch('4').text : fetch('2').text
end
measure_to() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 258
def measure_to
  between ? fetch('5').text : fetch('3').text
end
model() click to toggle source
# 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
stub?() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 181
def stub?
  true
end
text() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 262
def text
  [value1, between, value2, measure_from].compact.join(' ')
end
to() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 272
def to
  fetch_date('4', '5', '6') || Date.today
end
url_for(symbol, lang = 'en') click to toggle source

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
value() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 276
def value
  (to - from).to_i / 365 # FIXME: obviously
end
value1() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 235
def value1
  fetch('1').text
end
value2() click to toggle source
# File lib/infoboxer/definitions/en.wikipedia.org.rb, line 250
def value2
  between ? fetch('3').text : nil
end
wiki(api_url, **options) click to toggle source

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
wikia(*domains) click to toggle source

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
wikis() click to toggle source
# File lib/infoboxer.rb, line 68
def wikis
  @wikis ||= {}
end