Class: Txgh::MergeCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/txgh/merge_calculator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head_contents, diff_point_contents, diff_hash) ⇒ MergeCalculator

Merges are based on diffs. Whatever was added/removed/modified between two resources is represented by the diff, while the resources themselves are what gets merged. This class uses the given diff to apply one resource’s phrases over the top of another.

head_contents: translated contents in HEAD diff_point_contents: translated contents in diff point, eg. master diff_hash: what was added/removed/modified in the source



19
20
21
22
23
# File 'lib/txgh/merge_calculator.rb', line 19

def initialize(head_contents, diff_point_contents, diff_hash)
  @head_contents = head_contents
  @diff_point_contents = diff_point_contents
  @diff_hash = diff_hash
end

Instance Attribute Details

#diff_hashObject (readonly)

Returns the value of attribute diff_hash.



9
10
11
# File 'lib/txgh/merge_calculator.rb', line 9

def diff_hash
  @diff_hash
end

#diff_point_contentsObject (readonly)

Returns the value of attribute diff_point_contents.



9
10
11
# File 'lib/txgh/merge_calculator.rb', line 9

def diff_point_contents
  @diff_point_contents
end

#head_contentsObject (readonly)

Returns the value of attribute head_contents.



9
10
11
# File 'lib/txgh/merge_calculator.rb', line 9

def head_contents
  @head_contents
end

Class Method Details

.merge(head_contents, diff_point_contents, diff_hash) ⇒ Object



4
5
6
# File 'lib/txgh/merge_calculator.rb', line 4

def merge(head_contents, diff_point_contents, diff_hash)
  new(head_contents, diff_point_contents, diff_hash).merge
end

Instance Method Details

#mergeObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/txgh/merge_calculator.rb', line 25

def merge
  phrase_hash = diff_point_hash.dup
  update_added(phrase_hash)
  update_modified(phrase_hash)
  update_removed(phrase_hash)

  ResourceContents.from_phrase_list(
    head_contents.tx_resource, phrase_hash.values
  )
end