Class: Ripgrep::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ripgrep/result.rb

Defined Under Namespace

Modules: Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, error = '', exit_status: 0) ⇒ Result

Returns a new instance of Result.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ripgrep/result.rb', line 11

def initialize(result, error = '', exit_status: 0)
  @raw_result = result
  @raw_error = error
  @exit_status = exit_status

  # TODO: skip when not matching result. like a help or version.
  @matches = result.split("\n").map do |line|
    # TODO: implement Match class. make more rich and useful interface.
    file, *body = line.split(':')
    { file: file, body: body.join(':') }
  end

  case exit_status
  when Status::SUCCESS
  when Status::NO_MATCH
  when Status::ERROR
    raise Ripgrep::ResultError, error 
  else
    raise Ripgrep::ResultError, error 
  end
end

Instance Attribute Details

#exit_statusObject (readonly)

Returns the value of attribute exit_status.



9
10
11
# File 'lib/ripgrep/result.rb', line 9

def exit_status
  @exit_status
end

#matchesObject (readonly)

Returns the value of attribute matches.



9
10
11
# File 'lib/ripgrep/result.rb', line 9

def matches
  @matches
end

#raw_errorObject (readonly)

Returns the value of attribute raw_error.



9
10
11
# File 'lib/ripgrep/result.rb', line 9

def raw_error
  @raw_error
end

#raw_resultObject (readonly)

Returns the value of attribute raw_result.



9
10
11
# File 'lib/ripgrep/result.rb', line 9

def raw_result
  @raw_result
end

Instance Method Details

#linesObject



33
34
35
# File 'lib/ripgrep/result.rb', line 33

def lines
  @raw_result.to_s.split("\n")
end

#to_sObject



37
38
39
# File 'lib/ripgrep/result.rb', line 37

def to_s
  @raw_result.to_s
end