Class: Search

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton-get/searcher/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database, dev) ⇒ Search

Returns a new instance of Search.



9
10
11
12
# File 'lib/teuton-get/searcher/search.rb', line 9

def initialize(database, dev)
  @dev = dev
  @database = database
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/teuton-get/searcher/search.rb', line 7

def results
  @results
end

Instance Method Details

#call(reponame_filter, filters) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/teuton-get/searcher/search.rb', line 14

def call(reponame_filter, filters)
  @results = {}
  @database.keys.each do |reponame|
    if reponame_filter == :all || reponame.include?(reponame_filter)
      search_inside_repo(reponame, filters)
    end
  end
  sort_results
end

#show_jsonObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/teuton-get/searcher/search.rb', line 24

def show_json
  list = []
  @results.each do |i|
    list << {
      score: i[:score],
      reponame: i[:reponame],
      testname: i[:testname]
    }
  end
  puts list.to_json
end

#show_screenObject



36
37
38
39
40
41
42
# File 'lib/teuton-get/searcher/search.rb', line 36

def show_screen
  @results.each do |i|
    @dev.write ("(x%02d) " % i[:score]), color: :white
    reponame = TeutonGet::Format.colorize(i[:reponame], i[:repoindex])
    @dev.writeln "#{reponame}#{Settings::SEPARATOR}#{i[:testname]}"
  end
end