Class: Recall::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/recall/results.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

ALL =
[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, search_path) ⇒ Results

Returns a new instance of Results.



6
7
8
9
10
# File 'lib/recall/results.rb', line 6

def initialize(query, search_path)

  @query = query
  @search_path = search_path
end

Instance Attribute Details

#results_stringObject

Returns the value of attribute results_string.



2
3
4
# File 'lib/recall/results.rb', line 2

def results_string
  @results_string
end

Instance Method Details

#format_queryObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/recall/results.rb', line 24

def format_query
  if method? 
    a = @query.split('')
    a[0] = '\.'
    @query = a.join('')
  end

  if !symbol? 
    c = @query.split('')
    c.unshift('\b')
    c.push('\b')
    @query = c.join('')
  end
end

#get_full_snippetObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/recall/results.rb', line 57

def get_full_snippet 
  results = parse_results # array of Result structs

  results.each do |result| # iterate over the Result structs
  
    line_num = 0

    File.open("#{result.file_path}", "r") do |f|
      f.each_line do |line|
        line_num = line_num + 1 
        if line_num < (result.line_number.to_i - 5) || line_num > (result.line_number.to_i + 15)
          next
        else 
          result.full_code << line
        end
      end
    end

  end
end

#get_grep_resultsObject



39
40
41
42
# File 'lib/recall/results.rb', line 39

def get_grep_results
  format_query #                                   # /Users/samschlinkert/Documents/code/flatiron
  return `grep -r -n -i --include=*.rb --include=*.erb "#{@query}" #{@search_path} | sort -r`
end

#method?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/recall/results.rb', line 16

def method?
  @query[0] == '.'
end

#parse_resultsObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/recall/results.rb', line 46

def parse_results
  results = get_grep_results.split("\n")

  results.map do |result|
    line_array = []
    line_array = result.split(":")
    Result.new(line_array[0], line_array[1], line_array[2], [''])
  end 

end

#symbol?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/recall/results.rb', line 20

def symbol?
  @query[0] == ':'
end

#urlObject



12
13
14
# File 'lib/recall/results.rb', line 12

def url 
  "#{@query.downcase.gsub(" ", "_")}.html"
end