Class: Kumi::Core::Analyzer::AnalysisState

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/analyzer/analysis_state.rb

Overview

Simple immutable state wrapper to prevent accidental mutations between passes

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ AnalysisState

Returns a new instance of AnalysisState.



8
9
10
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 8

def initialize(data = {})
  @data = data.dup.freeze
end

Instance Method Details

#[](key) ⇒ Object

Get a value (same as hash access)



13
14
15
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 13

def [](key)
  @data[key]
end

#key?(key) ⇒ Boolean Also known as: has_key?

Check if key exists (same as hash)

Returns:

  • (Boolean)


18
19
20
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 18

def key?(key)
  @data.key?(key)
end

#keysObject

Get all keys (same as hash)



25
26
27
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 25

def keys
  @data.keys
end

#to_hObject

Convert back to hash for final result



35
36
37
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 35

def to_h
  @data.dup
end

#with(key, value) ⇒ Object

Create new state with additional data (simple and clean)



30
31
32
# File 'lib/kumi/core/analyzer/analysis_state.rb', line 30

def with(key, value)
  AnalysisState.new(@data.merge(key => value))
end