Class: I18nUno::Comparer

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_uno/comparer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, target_file) ⇒ Comparer

Returns a new instance of Comparer.



9
10
11
12
# File 'lib/i18n_uno/comparer.rb', line 9

def initialize(source_file, target_file)
  @source_file = source_file
  @target_file = target_file
end

Instance Attribute Details

#source_fileObject

Returns the value of attribute source_file.



7
8
9
# File 'lib/i18n_uno/comparer.rb', line 7

def source_file
  @source_file
end

#target_fileObject

Returns the value of attribute target_file.



7
8
9
# File 'lib/i18n_uno/comparer.rb', line 7

def target_file
  @target_file
end

Instance Method Details

#compareObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/i18n_uno/comparer.rb', line 14

def compare
  source_keys = flatten_keys(normalize_data(source_file.content_hash))
  target_keys = flatten_keys(normalize_data(target_file.content_hash))

  new_keys     = compare_keys(target_keys, source_keys)
  removed_keys = compare_keys(source_keys, target_keys)

  I18nUno::Delta.new(
    new_keys: new_keys,
    removed_keys: removed_keys,
    target_keys_size: target_keys.size
  )
end