Class: Result

Inherits:
Struct show all
Defined in:
lib/search_tools.rb

Overview

A struct which represents a search result. Will be documented much better soon.

Author:

  • Shreyan Jain

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#snippetString (readonly)

Returns the snippet of the search result.

Returns:

  • (String)

    the snippet of the search result.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/search_tools.rb', line 32

Result = Struct.new(:url, :title, :snippet) do
  # @return [String] An HTML representation of the search result, to be rendered in the results page.
  def to_html
    res = self
    mab do
      a(res.title, href: res.url)
      2.times { br }
      text res.url
      2.times { br }
      text res.snippet
      2.times { br }
    end
  end
end

#titleString (readonly)

Returns the title of the search result.

Returns:

  • (String)

    the title of the search result.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/search_tools.rb', line 32

Result = Struct.new(:url, :title, :snippet) do
  # @return [String] An HTML representation of the search result, to be rendered in the results page.
  def to_html
    res = self
    mab do
      a(res.title, href: res.url)
      2.times { br }
      text res.url
      2.times { br }
      text res.snippet
      2.times { br }
    end
  end
end

#urlString (readonly)

Returns the URL of the search result.

Returns:

  • (String)

    the URL of the search result.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/search_tools.rb', line 32

Result = Struct.new(:url, :title, :snippet) do
  # @return [String] An HTML representation of the search result, to be rendered in the results page.
  def to_html
    res = self
    mab do
      a(res.title, href: res.url)
      2.times { br }
      text res.url
      2.times { br }
      text res.snippet
      2.times { br }
    end
  end
end

Instance Method Details

#to_htmlString

Returns An HTML representation of the search result, to be rendered in the results page.

Returns:

  • (String)

    An HTML representation of the search result, to be rendered in the results page.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/search_tools.rb', line 34

def to_html
  res = self
  mab do
    a(res.title, href: res.url)
    2.times { br }
    text res.url
    2.times { br }
    text res.snippet
    2.times { br }
  end
end