Class: Ripgrep::Result
- Inherits:
-
Object
- Object
- Ripgrep::Result
- Defined in:
- lib/ripgrep/result.rb
Defined Under Namespace
Modules: Status
Instance Attribute Summary collapse
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#raw_error ⇒ Object
readonly
Returns the value of attribute raw_error.
-
#raw_result ⇒ Object
readonly
Returns the value of attribute raw_result.
Instance Method Summary collapse
-
#initialize(result, error = '', exit_status: 0) ⇒ Result
constructor
A new instance of Result.
- #lines ⇒ Object
- #to_s ⇒ Object
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_status ⇒ Object (readonly)
Returns the value of attribute exit_status.
9 10 11 |
# File 'lib/ripgrep/result.rb', line 9 def exit_status @exit_status end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
9 10 11 |
# File 'lib/ripgrep/result.rb', line 9 def matches @matches end |
#raw_error ⇒ Object (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_result ⇒ Object (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
#lines ⇒ Object
33 34 35 |
# File 'lib/ripgrep/result.rb', line 33 def lines @raw_result.to_s.split("\n") end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/ripgrep/result.rb', line 37 def to_s @raw_result.to_s end |