Sha256: 5f3035af5875a2ebb3e5f7d76930d5ffb5f3feda8a0b0180a5953b4df5e68e61

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Reality
  module Describers
    class WikimediaCommons < Abstract::MediaWiki
      API_URL = Infoboxer.url_for(:commons)

      private

      def prefix
        'wikimedia-commons'
      end

      # FIXME: duplicates with Wikipedia

      def setup_request(request)
        request
          .prop(:pageimages).prop(:thumbnail, :original) # main image of the page
      end

      def parse_page(page)
        parse_meta(page).map { |params| obs(page.title, *params) }
      end

      def parse_meta(page)
        [
          ['meta.title', page.title],
          ['meta.url', page.url],
          ['meta.image', page.source.dig('original', 'source')],
          ['meta.thumb', page.source.dig('thumbnail', 'source')],
          *category_meta(page)
        ].select(&:last)
      end

      def category_meta(page)
        return [] unless page.category?
        [['meta.pages', Query.new(prefix, category: page.title)]]
      end
    end
  end
end

Reality.describers['wikimedia-commons'] = Reality::Describers::WikimediaCommons.new

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reality-0.1.0.alpha3 lib/reality/describers/wikimedia_commons.rb
reality-0.1.0.alpha2 lib/reality/describers/wikimedia_commons.rb
reality-0.1.0.alpha lib/reality/describers/wikimedia_commons.rb