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:, type:) ⇒ 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_types, 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/filter.rb', line 69 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 =~ Regexp.new([:select_by_name_regex])) end unless name.present? && filters[:name_exclude].nil? && [:exclude_by_name_regex].present? return end filters[:name_exclude] = !!(name =~ Regexp.new([: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.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/filter.rb', line 124 def self.apply_other_filters(, filters, fcb) name = fcb.oname shell = fcb.shell filters[:fcb_chrome] = fcb.fetch(:chrome, false) filters[:shell_default] = (fcb.type == BlockType::SHELL) if [:block_disable_match].present? && fcb.start_line =~ Regexp.new([:block_disable_match]) fcb.disabled = TtyMenu::DISABLE end return unless name.present? if [:hide_blocks_by_name] filters[:hidden_name] = !!([:block_name_hidden_match].present? && name =~ Regexp.new([:block_name_hidden_match])) end filters[:include_name] = !!([:block_name_include_match].present? && name =~ Regexp.new([:block_name_include_match])) filters[:wrap_name] = !!([:block_name_wrapper_match].present? && name =~ Regexp.new([:block_name_wrapper_match])) end |
.apply_shell_filters(options, filters, shell:, type:) ⇒ 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.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/filter.rb', line 96 def self.apply_shell_filters(, filters, shell:, type:) raise if shell.nil? filters[:shell_expect] = type == 'expect' if shell.empty? && [:bash_only] filters[:shell_exclude] = true return end if shell.present? && [:select_by_shell_regex].present? filters[:shell_select] = !!(shell =~ Regexp.new([:select_by_shell_regex])) end return unless shell.present? && [:exclude_by_shell_regex].present? filters[:shell_exclude] = !!(shell =~ Regexp.new([: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.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/filter.rb', line 158 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/filter.rb', line 36 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 } apply_name_filters(, filters, fcb.oname) apply_shell_filters( , filters, shell: fcb.shell || '', type: fcb.type || '' ) 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
191 192 193 194 195 196 197 |
# File 'lib/filter.rb', line 191 def self.(, fcb, match_patterns) return false unless fcb.type == BlockType::SHELL match_patterns.any? do |pattern| [pattern].present? && fcb.oname =~ /#{[pattern]}/ end end |
.yield_to_block_if_applicable(fcb, selected_types, 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_types
include :blocks,
and if the fcb_select? method returns true for the given fcb.
210 211 212 213 214 215 216 217 |
# File 'lib/filter.rb', line 210 def self.yield_to_block_if_applicable(fcb, selected_types, configuration = {}, &block) if block_given? && block_type_selected?(selected_types, :blocks) && fcb_select?(configuration, fcb) block.call :blocks, fcb end end |