Class: Ferret::Search::Explanation

Inherits:
Object
  • Object
show all
Defined in:
lib/ferret/search/explanation.rb

Overview

Expert: Describes the score computation for document and query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, description = nil) ⇒ Explanation

Returns a new instance of Explanation.



6
7
8
9
10
# File 'lib/ferret/search/explanation.rb', line 6

def initialize(value = nil, description = nil) 
  @value = value
  @description = description
  @details = []
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/ferret/search/explanation.rb', line 4

def description
  @description
end

#detailsObject

Returns the value of attribute details.



4
5
6
# File 'lib/ferret/search/explanation.rb', line 4

def details
  @details
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/ferret/search/explanation.rb', line 4

def value
  @value
end

Instance Method Details

#<<(detail) ⇒ Object



12
13
14
# File 'lib/ferret/search/explanation.rb', line 12

def <<(detail)
  @details << detail
end

#to_htmlObject

Render an explanation as HTML.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ferret/search/explanation.rb', line 28

def to_html() 
  buffer = "<ul>\n"
  buffer << "<li>#{@value} = #{@description}</li>\n"

  @details.each do |detail|
    buffer << detail.to_html
  end

  buffer << "</ul>\n"

  return buffer
end

#to_s(depth = 0) ⇒ Object

Render an explanation as text.



17
18
19
20
21
22
23
24
25
# File 'lib/ferret/search/explanation.rb', line 17

def to_s(depth = 0) 
  buffer = "  " * depth
  buffer << "#{@value} = #{@description}\n"

  @details.each do |detail|
    buffer << detail.to_s(depth + 1)
  end
  return buffer
end