Class: Madness::Search

Inherits:
Object
  • Object
show all
Includes:
ServerHelper
Defined in:
lib/madness/search.rb

Instance Method Summary collapse

Methods included from ServerHelper

#docroot, #log

Constructor Details

#initialize(path = nil) ⇒ Search

Returns a new instance of Search.



6
7
8
# File 'lib/madness/search.rb', line 6

def initialize(path=nil)
  @path = path || docroot
end

Instance Method Details

#indexObject



10
11
12
# File 'lib/madness/search.rb', line 10

def index
  @index ||= index!
end

#search(query) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/madness/search.rb', line 14

def search(query)
  query = query.downcase
  result = {}

  index.each do |file, content|
    file = file.remove("#{@path}/")[0...-3]
    url = file_url file
    label = file_label file
    next unless content.include? query
    result[label] = url
  end

  result
end