Class: DumpCleaner::Cleanup::StepContext

Inherits:
Object
  • Object
show all
Includes:
Inspection
Defined in:
lib/dump_cleaner/cleanup/step_context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspection

#inspect_step_context, #subset, #truncate

Constructor Details

#initialize(type:, cleanup_data:, orig_value: nil, record: {}, repetition: 0) ⇒ StepContext

Returns a new instance of StepContext.



13
14
15
16
17
18
19
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 13

def initialize(type:, cleanup_data:, orig_value: nil, record: {}, repetition: 0)
  @type = type
  @cleanup_data = cleanup_data
  @orig_value = @current_value = orig_value
  @record = record
  @repetition = repetition
end

Instance Attribute Details

#cleanup_dataObject

Returns the value of attribute cleanup_data.



10
11
12
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 10

def cleanup_data
  @cleanup_data
end

#current_valueObject

Returns the value of attribute current_value.



10
11
12
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 10

def current_value
  @current_value
end

#orig_valueObject (readonly)

Returns the value of attribute orig_value.



11
12
13
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 11

def orig_value
  @orig_value
end

#recordObject (readonly)

Returns the value of attribute record.



11
12
13
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 11

def record
  @record
end

#repetitionObject

Returns the value of attribute repetition.



10
11
12
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 10

def repetition
  @repetition
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 11

def type
  @type
end

Class Method Details

.new_from(step_context, **params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 21

def self.new_from(step_context, **params)
  context_copy = step_context.dup
  new_context = new(orig_value: params[:orig_value] || context_copy.orig_value,
                    type: params[:type] || context_copy.type,
                    cleanup_data: params[:cleanup_data] || context_copy.cleanup_data,
                    record: params[:record] || context_copy.record,
                    repetition: params[:repetition] || context_copy.repetition)
  new_context.current_value = params[:current_value] || context_copy.current_value
  new_context
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 41

def ==(other)
  to_h == other.to_h
end

#pretty_print(pp) ⇒ Object



37
38
39
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 37

def pretty_print(pp)
  to_h(subset: true).pretty_print(pp)
end

#to_h(subset: false) ⇒ Object



32
33
34
35
# File 'lib/dump_cleaner/cleanup/step_context.rb', line 32

def to_h(subset: false)
  { orig_value:, current_value:, type:, record:, repetition:,
    cleanup_data: subset ? subset(cleanup_data) : cleanup_data }
end