Class: Ace::Search::Models::SearchResult
- Inherits:
-
Object
- Object
- Ace::Search::Models::SearchResult
- Defined in:
- lib/ace/search/models/search_result.rb
Overview
SearchResult represents a single search result item This is a model - pure data structure with no behavior
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#match_end ⇒ Object
readonly
Returns the value of attribute match_end.
-
#match_start ⇒ Object
readonly
Returns the value of attribute match_start.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#submatches ⇒ Object
readonly
Returns the value of attribute submatches.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .directory(path, metadata = {}) ⇒ Object
- .file(path, metadata = {}) ⇒ Object
- .match(path, line_number, content, options = {}) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #basename ⇒ Object
- #directory? ⇒ Boolean
- #dirname ⇒ Object
- #extension ⇒ Object
- #file? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(type:, path:, line_number: nil, content: nil, column: nil, match_start: nil, match_end: nil, submatches: nil, metadata: {}) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #match? ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(type:, path:, line_number: nil, content: nil, column: nil, match_start: nil, match_end: nil, submatches: nil, metadata: {}) ⇒ SearchResult
Returns a new instance of SearchResult.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ace/search/models/search_result.rb', line 12 def initialize(type:, path:, line_number: nil, content: nil, column: nil, match_start: nil, match_end: nil, submatches: nil, metadata: {}) @type = type @path = path @line_number = line_number @content = content @column = column @match_start = match_start @match_end = match_end @submatches = submatches || [] @metadata = || {} end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def column @column end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def content @content end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def line_number @line_number end |
#match_end ⇒ Object (readonly)
Returns the value of attribute match_end.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def match_end @match_end end |
#match_start ⇒ Object (readonly)
Returns the value of attribute match_start.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def match_start @match_start end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def path @path end |
#submatches ⇒ Object (readonly)
Returns the value of attribute submatches.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def submatches @submatches end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/ace/search/models/search_result.rb', line 9 def type @type end |
Class Method Details
.directory(path, metadata = {}) ⇒ Object
87 88 89 |
# File 'lib/ace/search/models/search_result.rb', line 87 def self.directory(path, = {}) new(type: :directory, path: path, metadata: ) end |
.file(path, metadata = {}) ⇒ Object
69 70 71 |
# File 'lib/ace/search/models/search_result.rb', line 69 def self.file(path, = {}) new(type: :file, path: path, metadata: ) end |
.match(path, line_number, content, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ace/search/models/search_result.rb', line 73 def self.match(path, line_number, content, = {}) new( type: :match, path: path, line_number: line_number, content: content, column: [:column], match_start: [:match_start], match_end: [:match_end], submatches: [:submatches], metadata: [:metadata] || {} ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
91 92 93 94 95 96 97 98 99 |
# File 'lib/ace/search/models/search_result.rb', line 91 def ==(other) return false unless other.is_a?(SearchResult) @type == other.type && @path == other.path && @line_number == other.line_number && @content == other.content && @column == other.column end |
#basename ⇒ Object
37 38 39 |
# File 'lib/ace/search/models/search_result.rb', line 37 def basename File.basename(@path) end |
#directory? ⇒ Boolean
33 34 35 |
# File 'lib/ace/search/models/search_result.rb', line 33 def directory? @type == :directory end |
#dirname ⇒ Object
41 42 43 |
# File 'lib/ace/search/models/search_result.rb', line 41 def dirname File.dirname(@path) end |
#extension ⇒ Object
45 46 47 48 |
# File 'lib/ace/search/models/search_result.rb', line 45 def extension ext = File.extname(@path) ext.empty? ? "" : ext[1..] end |
#file? ⇒ Boolean
25 26 27 |
# File 'lib/ace/search/models/search_result.rb', line 25 def file? @type == :file end |
#hash ⇒ Object
101 102 103 |
# File 'lib/ace/search/models/search_result.rb', line 101 def hash [@type, @path, @line_number, @content, @column].hash end |
#match? ⇒ Boolean
29 30 31 |
# File 'lib/ace/search/models/search_result.rb', line 29 def match? @type == :match end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ace/search/models/search_result.rb', line 50 def to_h { type: @type, path: @path, line_number: @line_number, content: @content, column: @column, match_start: @match_start, match_end: @match_end, submatches: @submatches, metadata: @metadata } end |
#to_json(*args) ⇒ Object
64 65 66 67 |
# File 'lib/ace/search/models/search_result.rb', line 64 def to_json(*args) require "json" to_h.to_json(*args) end |