Class: WhatIs::ThisIs::Ambigous

Inherits:
Object
  • Object
show all
Defined in:
lib/whatis/thisis/ambigous.rb

Overview

Note:

This functionality (special wrapper for disambiguation pages) works only for those language Wikis which have their “disambiguation” category known to ‘WhatIs`. See AMBIGOUS_CATEGORIES.

Represents disambiguation page.

You should never create instances of this class directly, but rather obtain it from WhatIs#this and WhatIs#these.

‘Ambigous` consists of #variants, each of them represented by a Link which can be resolved.

Examples:

a = WhatIs.this('Bela Crkva')
# => #<ThisIs::Ambigous Bela Crkva (6 options)>
a.describe
# => Bela Crkva: ambigous (6 options)
#  #<ThisIs::Link Bela Crkva, Banat>: Bela Crkva, Banat, a town in Vojvodina, Serbia
#  #<ThisIs::Link Bela Crkva, Krivogaštani>: Bela Crkva, Krivogaštani, a village in the Municipality of Krivogaštani, Macedonia
#  #<ThisIs::Link Bela Crkva (Krupanj)>: Bela Crkva (Krupanj), a village in the Mačva District of Serbia
#  #<ThisIs::Link Toplička Bela Crkva>: Toplička Bela Crkva, original name of the city of Kuršumlija, Serbia
#  #<ThisIs::Link See also/Bila Tserkva>: Bila Tserkva (Біла Церква), a city in the Kiev Oblast of Ukraine
#  #<ThisIs::Link See also/Byala Cherkva>: Byala Cherkva, a town in the Veliko Turnovo oblast of Bulgaria
#
#  Usage: .variants[0].resolve, .resolve_all

a.variants[0]
# => #<ThisIs::Link Bela Crkva, Banat>
a.variants[0].resolve
# => #<ThisIs Bela Crkva, Banat [img] {44.897500,21.416944}>
a.variants[0].resolve(categories: true)
# => #<ThisIs Bela Crkva, Banat, 5 categories [img] {44.897500,21.416944}>
a.resolve_all
# => {"Bela Crkva, Banat"=>#<ThisIs Bela Crkva, Banat [img] {44.897500,21.416944}>, "Bela Crkva, Krivogaštani"=>#<ThisIs Bela Crkva, Krivogaštani {41.280833,21.345278}>, "Bela Crkva (Krupanj)"=>#<ThisIs Bela Crkva (Krupanj) [img] {44.395000,19.479400}>, "Toplička Bela Crkva"=>#<ThisIs Kuršumlija [img] {43.150000,21.266667}>, "Bila Tserkva"=>#<ThisIs Bila Tserkva [img] {49.798889,30.115278}>, "Byala Cherkva"=>#<ThisIs Byala Cherkva [img] {43.200000,25.300000}>}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, page) ⇒ Ambigous

Returns a new instance of Ambigous.



50
51
52
53
54
# File 'lib/whatis/thisis/ambigous.rb', line 50

def initialize(owner, page)
  @owner = owner
  @page = page
  @variants = extract_variants
end

Instance Attribute Details

#pageInfoboxer::MediaWiki::Page (readonly)

Returns:

  • (Infoboxer::MediaWiki::Page)


41
42
43
# File 'lib/whatis/thisis/ambigous.rb', line 41

def page
  @page
end

#variantsArray<ThisIs::Link> (readonly)

Each link can be resolved individually, like ‘ambigous.variants.resolve`, or you can resolve them all at once with #resolve_all.

Returns:



47
48
49
# File 'lib/whatis/thisis/ambigous.rb', line 47

def variants
  @variants
end

Instance Method Details

#describe(help: true) ⇒ Description

Returns:



86
87
88
89
90
91
92
# File 'lib/whatis/thisis/ambigous.rb', line 86

def describe(help: true)
  Description.new(
    "#{self}\n" +
      variants.map { |link| "  #{link.inspect}: #{link.description}" }.join("\n") +
      describe_help(help)
  )
end

#inspectString

Returns:

  • (String)


62
63
64
# File 'lib/whatis/thisis/ambigous.rb', line 62

def inspect
  "#<ThisIs::Ambigous #{title} (#{variants.count} options)>"
end

#resolve_all(**options) ⇒ Hash{String => ThisIs}

Resolves all ambigous variants with one query. See WhatIs#this for options explanation.

Parameters:

  • options (Hash)

Options Hash (**options):

  • :languages (true, String, Symbol)
  • :categories (true, false)

Returns:



101
102
103
# File 'lib/whatis/thisis/ambigous.rb', line 101

def resolve_all(**options)
  @owner.these(*variants.map(&:title), **options)
end

#titleString

Returns:

  • (String)


57
58
59
# File 'lib/whatis/thisis/ambigous.rb', line 57

def title
  page.title
end

#to_hHash

Returns:

  • (Hash)


72
73
74
75
76
77
78
# File 'lib/whatis/thisis/ambigous.rb', line 72

def to_h
  {
    type: 'ThisIs::Ambigous',
    title: title,
    variants: variants.map(&:to_s)
  }
end

#to_json(opts) ⇒ String

Returns:

  • (String)


81
82
83
# File 'lib/whatis/thisis/ambigous.rb', line 81

def to_json(opts)
  to_h.to_json(opts)
end

#to_sString

Returns:

  • (String)


67
68
69
# File 'lib/whatis/thisis/ambigous.rb', line 67

def to_s
  "#{title}: ambigous (#{variants.count} options)"
end