Module: RTM::Merging::Name

Defined in:
lib/rtm/activerecord/merging.rb

Instance Method Summary collapse

Instance Method Details

#merge(other) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rtm/activerecord/merging.rb', line 239

def merge(other)
  # The procedure for merging two topic name items A and B is given below.
  # -> we will instead just modify a

  # 1. Create a new topic name item C.
  # 2. Set C's [value] property to the value of the [value] property of A. B's value is equal that of A and need not be taken into account.
  # 3. Set C's [type] property to the value of the [type] property of A. B's value is equal that of A and need not be taken into account.
  # 4. Set C's [scope] property to the value of the [scope] property of A. B's value is equal that of A and need not be taken into account.
  # -> nothing to do till here

  # 5. Set C's [variants] property to the union of the [variants] properties of A and B.
  #self.variants.add_all other.variants
  count = RTM::AR::TMDM::Variant.move_all(["name_id", other.__getobj__.id, self.__getobj__.id])
  if count != 0 && count != variants.size
    variants.each_with_index do |v,i|
      (i+1).upto(variants.size-1) do |j|
        if v == variants[j]
          v.merge variants[j]
        end
      end
    end
  end

  # 6. Set C's [reifier] property to the value of A's [reifier] property if it is not null, and to the value of B's [reifier] property if A's property is null. If both A and B have non-null values, the topic items shall be merged, and the topic item resulting from the merge be set as the value of C's [reifier] property.
  self.merge_reifiable other

  # 7. Set C's [item identifiers] property to the union of the value of the [item identifiers] properties of A and B.
  self.merge_item_identifiers other

  # 8. Remove A and B from the [topic names] property of the topic item in their [parent] properties, and add C.
  #self.parent.names.remove other

  # let the wrapper point to the new object
  #other.__setobj__(self.__getobj__) if self.respond_to?(:__getobj__) && other.respond_to?(:__setobj__)
  self.merge_rewrap other

  self
end