Class: Canon::Config::MatchConfig
- Inherits:
-
Object
- Object
- Canon::Config::MatchConfig
- Defined in:
- lib/canon/config.rb
Overview
Match configuration for comparison behavior
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #apply_profile_data(data) ⇒ Object
- #clear_profile! ⇒ Object
-
#collapse_whitespace_elements ⇒ Object
Element names where whitespace is COLLAPSED (HTML-style behavior).
-
#initialize(format = nil) ⇒ MatchConfig
constructor
A new instance of MatchConfig.
-
#preserve_whitespace_elements ⇒ Object
Element names where whitespace is PRESERVED exactly (no manipulation).
-
#profile ⇒ Object
Profile accessor with ENV override support.
- #profile=(value) ⇒ Object
-
#profile_options ⇒ Hash
Return all profile-sourced values from the resolver, excluding the :profile key itself (which is accessed via #profile).
- #reset! ⇒ Object
-
#strip_whitespace_elements ⇒ Object
Element names where whitespace-only text nodes are STRIPPED.
-
#to_h ⇒ Object
Build match options from profile and options.
Constructor Details
#initialize(format = nil) ⇒ MatchConfig
Returns a new instance of MatchConfig.
173 174 175 176 177 |
# File 'lib/canon/config.rb', line 173 def initialize(format = nil) @format = format @resolver = build_resolver(format) @options = {} end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
171 172 173 |
# File 'lib/canon/config.rb', line 171 def @options end |
Instance Method Details
#apply_profile_data(data) ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/canon/config.rb', line 233 def apply_profile_data(data) return unless data data.each do |key, value| sym_key = key.to_sym converted = value.is_a?(String) ? value.to_sym : value @resolver.set_profile(sym_key, converted) end end |
#clear_profile! ⇒ Object
243 244 245 |
# File 'lib/canon/config.rb', line 243 def clear_profile! @resolver.clear_profile! end |
#collapse_whitespace_elements ⇒ Object
Element names where whitespace is COLLAPSED (HTML-style behavior). Multiple whitespace chars collapse to single space; boundaries preserved.
216 217 218 |
# File 'lib/canon/config.rb', line 216 def collapse_whitespace_elements @resolver.resolve(:collapse_whitespace_elements) || [] end |
#preserve_whitespace_elements ⇒ Object
Element names where whitespace is PRESERVED exactly (no manipulation). All whitespace characters are significant in these elements.
210 211 212 |
# File 'lib/canon/config.rb', line 210 def preserve_whitespace_elements @resolver.resolve(:preserve_whitespace_elements) || [] end |
#profile ⇒ Object
Profile accessor with ENV override support
189 190 191 |
# File 'lib/canon/config.rb', line 189 def profile @resolver.resolve(:profile) end |
#profile=(value) ⇒ Object
193 194 195 |
# File 'lib/canon/config.rb', line 193 def profile=(value) @resolver.set_programmatic(:profile, value) end |
#profile_options ⇒ Hash
Return all profile-sourced values from the resolver, excluding the :profile key itself (which is accessed via #profile). These are the YAML-profile settings (e.g., preserve_whitespace_elements) that are stored in the resolver’s profile layer but not exposed through the built-in MATCH_PROFILES system.
204 205 206 |
# File 'lib/canon/config.rb', line 204 def @resolver.profile.except(:profile) end |
#reset! ⇒ Object
183 184 185 186 |
# File 'lib/canon/config.rb', line 183 def reset! @resolver = build_resolver(@format) @options = {} end |
#strip_whitespace_elements ⇒ Object
Element names where whitespace-only text nodes are STRIPPED.
221 222 223 |
# File 'lib/canon/config.rb', line 221 def strip_whitespace_elements @resolver.resolve(:strip_whitespace_elements) || [] end |
#to_h ⇒ Object
Build match options from profile and options
226 227 228 229 230 231 |
# File 'lib/canon/config.rb', line 226 def to_h result = {} result[:match_profile] = profile if profile result[:match] = @options if @options && !@options.empty? result end |