Class: WhatIs::ThisIs::NotFound

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

Overview

Represents not found page, allowing to search for term through Wikipedia API.

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

Examples:

notfound = WhatIs.this('Guardians Of The Galaxy') # Wikipedia fetching is case-sensitive
# => #<ThisIs::NotFound Guardians Of The Galaxy>
notfound.search(3)
# => [#<ThisIs::Ambigous Guardians of the Galaxy (11 options)>, #<ThisIs Guardians of the Galaxy (film)>, #<ThisIs Guardians of the Galaxy Vol. 2>]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, title) ⇒ NotFound

Returns a new instance of NotFound.



19
20
21
22
# File 'lib/whatis/thisis/notfound.rb', line 19

def initialize(owner, title)
  @owner = owner
  @title = title
end

Instance Attribute Details

#titleString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/whatis/thisis/notfound.rb', line 16

def title
  @title
end

Instance Method Details

#describe(help: true) ⇒ Description

Returns:



58
59
60
# File 'lib/whatis/thisis/notfound.rb', line 58

def describe(help: true)
  Description.new("#{self}#{describe_help(help)}")
end

#inspectString

Returns:

  • (String)


38
39
40
# File 'lib/whatis/thisis/notfound.rb', line 38

def inspect
  "#<ThisIs::NotFound #{title}>"
end

#search(limit = 5, **options) ⇒ Array<ThisIs, ThisIs::Ambigous>

Searches for requested entity name through Wikipedia API.

See WhatIs#this for options explanation.

Parameters:

  • limit (Integer) (defaults to: 5)

    Number of results to return.

  • options (Hash)

Options Hash (**options):

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

Returns:



33
34
35
# File 'lib/whatis/thisis/notfound.rb', line 33

def search(limit = 5, **options)
  @owner.search(title, limit, **options)
end

#to_hHash

Returns:

  • (Hash)


48
49
50
# File 'lib/whatis/thisis/notfound.rb', line 48

def to_h
  {type: 'ThisIs::NotFound', title: title}
end

#to_json(opts) ⇒ String

Returns:

  • (String)


53
54
55
# File 'lib/whatis/thisis/notfound.rb', line 53

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

#to_sString

Returns:

  • (String)


43
44
45
# File 'lib/whatis/thisis/notfound.rb', line 43

def to_s
  "#{title}: not found"
end