Class: MismatchInspectable::InspectionOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/mismatch_inspectable/inspection_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix: "", recursive: false, include_class: true, format: :array) ⇒ InspectionOptions

Returns a new instance of InspectionOptions.



7
8
9
10
11
12
# File 'lib/mismatch_inspectable/inspection_options.rb', line 7

def initialize(prefix: "", recursive: false, include_class: true, format: :array)
  @recursive = recursive
  @include_class = include_class
  @prefix = prefix
  @format = format
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/mismatch_inspectable/inspection_options.rb', line 5

def format
  @format
end

#include_classObject

Returns the value of attribute include_class.



5
6
7
# File 'lib/mismatch_inspectable/inspection_options.rb', line 5

def include_class
  @include_class
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/mismatch_inspectable/inspection_options.rb', line 5

def options
  @options
end

#prefixObject

Returns the value of attribute prefix.



5
6
7
# File 'lib/mismatch_inspectable/inspection_options.rb', line 5

def prefix
  @prefix
end

#recursiveObject

Returns the value of attribute recursive.



5
6
7
# File 'lib/mismatch_inspectable/inspection_options.rb', line 5

def recursive
  @recursive
end

Instance Method Details

#comparable_prefixObject



33
34
35
36
# File 'lib/mismatch_inspectable/inspection_options.rb', line 33

def comparable_prefix
  prefixes = prefix.split(".")
  prefixes.length >= 2 ? prefixes[-1] : prefix
end

#formatterObject



14
15
16
# File 'lib/mismatch_inspectable/inspection_options.rb', line 14

def formatter
  @formatter ||= FormatBuilder.new(format).formatter
end

#to_hObject



18
19
20
21
22
23
24
25
# File 'lib/mismatch_inspectable/inspection_options.rb', line 18

def to_h
  {
    recursive:,
    include_class:,
    prefix:,
    format:
  }
end

#update_prefix(target_class) ⇒ Object



27
28
29
30
31
# File 'lib/mismatch_inspectable/inspection_options.rb', line 27

def update_prefix(target_class)
  if include_class && comparable_prefix != "#{target_class.class}#"
    self.prefix = "#{prefix}#{target_class.class}#"
  end
end