class Object

Public Instance Methods

data_merge(file_current, file_server) click to toggle source
# File lib/shunkuntype/merge.rb, line 3
def data_merge(file_current, file_server)
  all_data=[]
  i,j=0,0
  while (file_current.length > i) and (file_server.length > j) do
    line_current,line_server = file_current[i], file_server[j]
    break if line_current=="\n" or line_server=="\n"
    time_current=Time.parse(line_current.split(',')[0])
    time_server=Time.parse(line_server.split(',')[0])
    if time_current == time_server then
      all_data << line_current
      i += 1
      j += 1
    elsif time_current < time_server then
      all_data << line_current
      i += 1
    else
      all_data << line_server
      j += 1
    end
  end
  while (file_current.length > i)
    all_data << file_current[i]
    i += 1
  end
  while (file_server.length > j)
    all_data <<  file_server[j]
    j += 1
  end
  all_data.delete("\n")
  return all_data.join
end