Class: WhatIs::ThisIs::Ambigous
- Inherits:
-
Object
- Object
- WhatIs::ThisIs::Ambigous
- Defined in:
- lib/whatis/thisis/ambigous.rb
Overview
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.
Instance Attribute Summary collapse
-
#page ⇒ Infoboxer::MediaWiki::Page
readonly
Original [Infoboxer page](www.rubydoc.info/gems/infoboxer/Infoboxer/MediaWiki/Page) data.
-
#variants ⇒ Array<ThisIs::Link>
readonly
Each link can be resolved individually, like ‘ambigous.variants.resolve`, or you can resolve them all at once with #resolve_all.
Instance Method Summary collapse
- #describe(help: true) ⇒ Description
-
#initialize(owner, page) ⇒ Ambigous
constructor
A new instance of Ambigous.
- #inspect ⇒ String
-
#resolve_all(**options) ⇒ Hash{String => ThisIs}
Resolves all ambigous variants with one query.
- #title ⇒ String
- #to_h ⇒ Hash
- #to_json(opts) ⇒ String
- #to_s ⇒ String
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
#page ⇒ Infoboxer::MediaWiki::Page (readonly)
Original [Infoboxer page](www.rubydoc.info/gems/infoboxer/Infoboxer/MediaWiki/Page) data.
41 42 43 |
# File 'lib/whatis/thisis/ambigous.rb', line 41 def page @page end |
#variants ⇒ Array<ThisIs::Link> (readonly)
Each link can be resolved individually, like ‘ambigous.variants.resolve`, or you can resolve them all at once with #resolve_all.
47 48 49 |
# File 'lib/whatis/thisis/ambigous.rb', line 47 def variants @variants end |
Instance Method Details
#describe(help: true) ⇒ Description
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 |
#inspect ⇒ 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.
101 102 103 |
# File 'lib/whatis/thisis/ambigous.rb', line 101 def resolve_all(**) @owner.these(*variants.map(&:title), **) end |
#title ⇒ String
57 58 59 |
# File 'lib/whatis/thisis/ambigous.rb', line 57 def title page.title end |
#to_h ⇒ 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
81 82 83 |
# File 'lib/whatis/thisis/ambigous.rb', line 81 def to_json(opts) to_h.to_json(opts) end |
#to_s ⇒ String
67 68 69 |
# File 'lib/whatis/thisis/ambigous.rb', line 67 def to_s "#{title}: ambigous (#{variants.count} options)" end |