Class: Recall::Results
- Inherits:
-
Object
- Object
- Recall::Results
- Defined in:
- lib/recall/results.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ALL =
[]
Instance Attribute Summary collapse
-
#results_string ⇒ Object
Returns the value of attribute results_string.
Instance Method Summary collapse
- #format_query ⇒ Object
- #get_full_snippet ⇒ Object
- #get_grep_results ⇒ Object
-
#initialize(query, search_path) ⇒ Results
constructor
A new instance of Results.
- #method? ⇒ Boolean
- #parse_results ⇒ Object
- #symbol? ⇒ Boolean
- #url ⇒ Object
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_string ⇒ Object
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_query ⇒ Object
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_snippet ⇒ Object
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_results ⇒ Object
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
16 17 18 |
# File 'lib/recall/results.rb', line 16 def method? @query[0] == '.' end |
#parse_results ⇒ Object
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
20 21 22 |
# File 'lib/recall/results.rb', line 20 def symbol? @query[0] == ':' end |
#url ⇒ Object
12 13 14 |
# File 'lib/recall/results.rb', line 12 def url "#{@query.downcase.gsub(" ", "_")}.html" end |