Class: Canon::Config::MatchConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/config.rb

Overview

Match configuration for comparison behavior

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format = nil) ⇒ MatchConfig

Returns a new instance of MatchConfig.



179
180
181
182
183
# File 'lib/canon/config.rb', line 179

def initialize(format = nil)
  @format = format
  @resolver = build_resolver(format)
  @options = {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



177
178
179
# File 'lib/canon/config.rb', line 177

def options
  @options
end

Instance Method Details

#apply_profile_data(data) ⇒ Object



239
240
241
242
243
244
245
246
247
# File 'lib/canon/config.rb', line 239

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



249
250
251
# File 'lib/canon/config.rb', line 249

def clear_profile!
  @resolver.clear_profile!
end

#collapse_whitespace_elementsObject

Element names where whitespace is COLLAPSED (HTML-style behavior). Multiple whitespace chars collapse to single space; boundaries preserved.



222
223
224
# File 'lib/canon/config.rb', line 222

def collapse_whitespace_elements
  @resolver.resolve(:collapse_whitespace_elements) || []
end

#preserve_whitespace_elementsObject

Element names where whitespace is PRESERVED exactly (no manipulation). All whitespace characters are significant in these elements.



216
217
218
# File 'lib/canon/config.rb', line 216

def preserve_whitespace_elements
  @resolver.resolve(:preserve_whitespace_elements) || []
end

#profileObject

Profile accessor with ENV override support



195
196
197
# File 'lib/canon/config.rb', line 195

def profile
  @resolver.resolve(:profile)
end

#profile=(value) ⇒ Object



199
200
201
# File 'lib/canon/config.rb', line 199

def profile=(value)
  @resolver.set_programmatic(:profile, value)
end

#profile_optionsHash

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.

Returns:

  • (Hash)

    Profile option key-values (excluding :profile)



210
211
212
# File 'lib/canon/config.rb', line 210

def profile_options
  @resolver.profile.except(:profile)
end

#reset!Object



189
190
191
192
# File 'lib/canon/config.rb', line 189

def reset!
  @resolver = build_resolver(@format)
  @options = {}
end

#strip_whitespace_elementsObject

Element names where whitespace-only text nodes are STRIPPED.



227
228
229
# File 'lib/canon/config.rb', line 227

def strip_whitespace_elements
  @resolver.resolve(:strip_whitespace_elements) || []
end

#to_hObject

Build match options from profile and options



232
233
234
235
236
237
# File 'lib/canon/config.rb', line 232

def to_h
  result = {}
  result[:match_profile] = profile if profile
  result[:match] = @options if @options && !@options.empty?
  result
end