Class: WhatIs::ThisIs::Link
- Inherits:
-
Object
- Object
- WhatIs::ThisIs::Link
- Defined in:
- lib/whatis/thisis/link.rb
Overview
Represents link to some entity that can be resolved to proper entity definition.
You should never create instances of this class directly, it occurs as variant links from Ambigous, and as ThisIs::languages links.
Instance Attribute Summary collapse
- #description ⇒ Object readonly
- #language ⇒ Object readonly
- #section ⇒ Object readonly
- #title ⇒ String (also: #to_s) readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(title, section: nil, owner: nil, language: nil, description: nil) ⇒ Link
constructor
A new instance of Link.
- #inspect ⇒ String
-
#resolve(**options) ⇒ ThisIs, ThisIs::Ambigous
Resolves the link, fetching entity from Wikipedia API.
Constructor Details
#initialize(title, section: nil, owner: nil, language: nil, description: nil) ⇒ Link
Returns a new instance of Link.
38 39 40 41 42 43 44 |
# File 'lib/whatis/thisis/link.rb', line 38 def initialize(title, section: nil, owner: nil, language: nil, description: nil) @owner = owner @title = title @language = language&.to_s @section = section unless section == '' @description = description end |
Instance Attribute Details
#description ⇒ Object (readonly)
35 36 37 |
# File 'lib/whatis/thisis/link.rb', line 35 def description @description end |
#language ⇒ Object (readonly)
31 32 33 |
# File 'lib/whatis/thisis/link.rb', line 31 def language @language end |
#section ⇒ Object (readonly)
35 36 37 |
# File 'lib/whatis/thisis/link.rb', line 35 def section @section end |
#title ⇒ String (readonly) Also known as: to_s
29 30 31 |
# File 'lib/whatis/thisis/link.rb', line 29 def title @title end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 |
# File 'lib/whatis/thisis/link.rb', line 70 def ==(other) other.is_a?(Link) && other.language == language && other.title == title end |
#inspect ⇒ String
47 48 49 |
# File 'lib/whatis/thisis/link.rb', line 47 def inspect "#<ThisIs::Link #{language&.append(':')}#{section&.append('/')}#{title}>" end |
#resolve(**options) ⇒ ThisIs, ThisIs::Ambigous
Resolves the link, fetching entity from Wikipedia API.
See WhatIs#this for options explanation.
61 62 63 64 65 66 |
# File 'lib/whatis/thisis/link.rb', line 61 def resolve(**) engine = @owner || language && WhatIs[language] or fail "Can't resolve #{inspect}" engine.this(title, **) end |