Class: MarkdownExec::Filter
Overview
Filter
The Filter class provides utilities to determine the inclusion of fenced code blocks (FCB) based on a set of provided options. The primary function, ‘fcb_select?`, checks various properties of an FCB and decides whether to include or exclude it.
:reek:UtilityFunction
Class Method Summary collapse
-
.apply_name_filters(options, filters, name) ⇒ Object
Applies name-based filters to determine whether to include or exclude a fenced code block (FCB) based on the block’s name and provided options.
-
.apply_other_filters(options, filters, fcb) ⇒ Object
Applies additional filters to determine whether to include or exclude a fenced code block (FCB) based on various criteria and provided options.
-
.apply_shell_filters(options, filters, shell) ⇒ Object
Applies shell-based filters to determine whether to include or exclude a fenced code block (FCB) based on the block’s shell type and provided options.
-
.evaluate_filters(options, filters) ⇒ Boolean
Evaluates the filter settings to make a final decision on whether to include or exclude a fenced code block (FCB) based on the provided options.
-
.fcb_select?(options, fcb) ⇒ Boolean
Determines whether to include or exclude a fenced code block (FCB) based on the provided options.
-
.prepared_not_in_menu?(options, fcb, match_patterns) ⇒ Boolean
check if a block is not in the menu based on multiple match patterns.
-
.yield_to_block_if_applicable(fcb, selected_messages, configuration = {}, &block) ⇒ Object
Yields to the provided block with specified parameters if certain conditions are met.
Class Method Details
.apply_name_filters(options, filters, name) ⇒ Object
Applies name-based filters to determine whether to include or exclude a fenced code block (FCB) based on the block’s name and provided options.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/filter.rb', line 59 def self.apply_name_filters(, filters, name) filters[:name_select] = true filters[:name_exclude] = false if name.present? && filters[:name_select].nil? && [:select_by_name_regex].present? filters[:name_select] = !!(name =~ /#{[:select_by_name_regex]}/) end unless name.present? && filters[:name_exclude].nil? && [:exclude_by_name_regex].present? return end filters[:name_exclude] = !!(name =~ /#{[:exclude_by_name_regex]}/) end |
.apply_other_filters(options, filters, fcb) ⇒ Object
Applies additional filters to determine whether to include or exclude a fenced code block (FCB) based on various criteria and provided options.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/filter.rb', line 110 def self.apply_other_filters(, filters, fcb) name = fcb.oname shell = fcb.fetch(:shell, '') filters[:fcb_chrome] = fcb.fetch(:chrome, false) if name.present? && [:hide_blocks_by_name] filters[:hidden_name] = !!([:block_name_hidden_match].present? && name =~ /#{[:block_name_hidden_match]}/) end filters[:include_name] = !!([:block_name_include_match].present? && name =~ /#{[:block_name_include_match]}/) filters[:wrap_name] = !!([:block_name_wrapper_match].present? && name =~ /#{[:block_name_wrapper_match]}/) filters[:shell_default] = (shell == BlockType::BASH) end |
.apply_shell_filters(options, filters, shell) ⇒ Object
Applies shell-based filters to determine whether to include or exclude a fenced code block (FCB) based on the block’s shell type and provided options.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/filter.rb', line 84 def self.apply_shell_filters(, filters, shell) filters[:shell_expect] = shell == 'expect' if shell.empty? && [:bash_only] filters[:shell_exclude] = true return end if shell.present? && [:select_by_shell_regex].present? filters[:shell_select] = !!(shell =~ /#{[:select_by_shell_regex]}/) end return unless shell.present? && [:exclude_by_shell_regex].present? filters[:shell_exclude] = !!(shell =~ /#{[:exclude_by_shell_regex]}/) end |
.evaluate_filters(options, filters) ⇒ Boolean
Evaluates the filter settings to make a final decision on whether to include or exclude a fenced code block (FCB) based on the provided options.
if it should be excluded.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/filter.rb', line 139 def self.evaluate_filters(, filters) if filters[:depth] == true false elsif filters[:fcb_chrome] == true ![:no_chrome] elsif [:exclude_expect_blocks] && filters[:shell_expect] == true false elsif filters[:hidden_name] == true false elsif filters[:include_name] == true true elsif filters[:wrap_name] == true true elsif filters[:name_exclude] == true || filters[:shell_exclude] == true || filters[:name_select] == false || filters[:shell_select] == false false elsif filters[:name_select] == true || filters[:shell_select] == true true elsif filters[:name_default] == false || filters[:shell_default] == false false else true end end |
.fcb_select?(options, fcb) ⇒ Boolean
Determines whether to include or exclude a fenced code block (FCB) based on the provided options.
it should be excluded.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/filter.rb', line 25 def self.fcb_select?(, fcb) filters = { name_default: true, name_exclude: nil, name_select: nil, shell_default: true, shell_exclude: nil, shell_select: nil, hidden_name: nil, include_name: nil, wrap_name: nil } name = fcb.oname shell = fcb.fetch(:shell, '') apply_name_filters(, filters, name) apply_shell_filters(, filters, shell) apply_other_filters(, filters, fcb) evaluate_filters(, filters) rescue StandardError warn("ERROR ** Filter::fcb_select?(); #{$!.inspect}") raise ArgumentError, $! end |
.prepared_not_in_menu?(options, fcb, match_patterns) ⇒ Boolean
check if a block is not in the menu based on multiple match patterns
170 171 172 173 174 175 176 |
# File 'lib/filter.rb', line 170 def self.(, fcb, match_patterns) return false unless fcb[:shell] == BlockType::BASH match_patterns.any? do |pattern| [pattern].present? && fcb[:oname] =~ /#{[pattern]}/ end end |
.yield_to_block_if_applicable(fcb, selected_messages, configuration = {}, &block) ⇒ Object
Yields to the provided block with specified parameters if certain conditions are met. The method checks if a block is given, if the selected_messages include :blocks, and if the fcb_select? method returns true for the given fcb.
185 186 187 188 189 190 |
# File 'lib/filter.rb', line 185 def self.yield_to_block_if_applicable(fcb, , configuration = {}, &block) if block_given? && .include?(:blocks) && fcb_select?(configuration, fcb) block.call :blocks, fcb end end |