Class: InertiaI18n::ScanResults

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_i18n/scan_results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScanResults

Returns a new instance of ScanResults.



7
8
9
10
11
12
# File 'lib/inertia_i18n/scan_results.rb', line 7

def initialize
  @files = {}
  @static_keys = Set.new
  @dynamic_patterns = []
  @occurrences = Hash.new { |h, k| h[k] = [] }
end

Instance Attribute Details

#dynamic_patternsObject (readonly)

Returns the value of attribute dynamic_patterns.



5
6
7
# File 'lib/inertia_i18n/scan_results.rb', line 5

def dynamic_patterns
  @dynamic_patterns
end

#filesObject (readonly)

Returns the value of attribute files.



5
6
7
# File 'lib/inertia_i18n/scan_results.rb', line 5

def files
  @files
end

#occurrencesObject (readonly)

Returns the value of attribute occurrences.



5
6
7
# File 'lib/inertia_i18n/scan_results.rb', line 5

def occurrences
  @occurrences
end

#static_keysObject (readonly)

Returns the value of attribute static_keys.



5
6
7
# File 'lib/inertia_i18n/scan_results.rb', line 5

def static_keys
  @static_keys
end

Instance Method Details

#add_file(file, keys) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/inertia_i18n/scan_results.rb', line 14

def add_file(file, keys)
  @files[file] = keys

  keys[:static].each do |usage|
    # Handle both legacy string keys and new usage objects
    if usage.is_a?(Hash)
      key = usage[:key]
      @static_keys.add(key)
      @occurrences[key] << {file: file, line: usage[:line]}
    else
      @static_keys.add(usage)
      @occurrences[usage] << {file: file, line: nil}
    end
  end

  config = InertiaI18n.configuration
  dynamic_keys_config = config.dynamic_keys || {}

  keys[:dynamic].each do |dynamic|
    pattern = dynamic[:pattern]
    @dynamic_patterns << dynamic

    if dynamic_keys_config.key?(pattern)
      dynamic_keys_config[pattern].each do |value|
        # Append value to pattern (e.g. "status." + "active" -> "status.active")
        expanded_key = "#{pattern}#{value}"
        @static_keys.add(expanded_key)
        @occurrences[expanded_key] << {file: file, line: dynamic[:line]}
      end
    end
  end
end

#to_hObject



51
52
53
54
55
56
57
58
# File 'lib/inertia_i18n/scan_results.rb', line 51

def to_h
  {
    files: @files,
    static_keys: @static_keys.to_a,
    dynamic_patterns: @dynamic_patterns,
    occurrences: @occurrences
  }
end

#used_keysObject



47
48
49
# File 'lib/inertia_i18n/scan_results.rb', line 47

def used_keys
  @static_keys
end