Class: MarkdownExec::SearchResultsReport

Inherits:
DirectorySearcher show all
Defined in:
lib/markdown_exec.rb

Instance Attribute Summary

Attributes inherited from DirectorySearcher

#filename_glob, #include_subdirectories, #paths, #pattern

Instance Method Summary collapse

Methods inherited from DirectorySearcher

#find_directory_names, #find_file_contents, #find_file_names, #initialize

Constructor Details

This class inherits a constructor from DirectorySearcher

Instance Method Details

#directory_names(search_options, highlight_value) ⇒ Object



181
182
183
184
185
186
187
188
# File 'lib/markdown_exec.rb', line 181

def directory_names(search_options, highlight_value)
  matched_directories = find_directory_names
  {
    section_title: 'directory names',
    data: matched_directories,
    formatted_text: [{ content: AnsiFormatter.new(search_options).format_and_highlight_array(matched_directories, highlight: [highlight_value]) }]
  }
end

#file_names(search_options, highlight_value) ⇒ Object



211
212
213
214
215
216
217
218
219
220
# File 'lib/markdown_exec.rb', line 211

def file_names(search_options, highlight_value)
  matched_files = find_file_names
  {
    section_title: 'file names',
    data: matched_files,
    formatted_text: [{ content: AnsiFormatter.new(search_options).format_and_highlight_array(
      matched_files, highlight: [highlight_value]
    ).join("\n") }]
  }
end

#found_in_block_names(search_options, highlight_value, formspec: '=%<index>4.d: %<line>s') ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/markdown_exec.rb', line 190

def found_in_block_names(search_options, highlight_value, formspec: '=%<index>4.d: %<line>s')
  matched_contents = (find_file_contents do |line|
                        read_block_name(line, search_options[:fenced_start_and_end_regex], search_options[:block_name_match], search_options[:block_name_nick_match])
                      end).map.with_index do |(file, contents), index|
    # [file, contents.map { |detail| format(formspec, detail.index, detail.line) }, index]
    [file, contents.map { |detail| format(formspec, { index: detail.index, line: detail.line }) }, index]
  end
  {
    section_title: 'block names',
    data: matched_contents.map(&:first),
    formatted_text: matched_contents.map do |(file, details, index)|
                      { header: format('- %3.d: %s', index + 1, file),
                        content: AnsiFormatter.new(search_options).format_and_highlight_array(
                          details,
                          highlight: [highlight_value]
                        ) }
                    end,
    matched_contents: matched_contents
  }
end

#read_block_name(line, fenced_start_and_end_regex, block_name_match, block_name_nick_match) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/markdown_exec.rb', line 222

def read_block_name(line, fenced_start_and_end_regex, block_name_match, block_name_nick_match)
  return unless line.match(fenced_start_and_end_regex)

  bm = extract_named_captures_from_option(line, block_name_match)
  return if bm.nil?

  name = bm[:title]

  if block_name_nick_match.present? && line =~ Regexp.new(block_name_nick_match)
    $~[0]
  else
    bm && bm[1] ? bm[:title] : name
  end
end