You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: change_resolver.rb
    path of file: ./repos/kontena/cli/lib/kontena/stacks
    
    the code of the file until where you have to start completion: require_relative 'stack_data_set'

module Kontena::Stacks
  class ChangeResolver

    attr_reader :old_data, :new_data

    # Creates a change analysis from two sets of stack data.
    # The format is a flat hash of all related stacks.
    #
    # @param old_data [DataSet,Hash]
    # @param new_data [DataSet,Ha
    
    def analyze
      old_names = old_data.stack_names
      new_names = new_data.stack_names

      removed_stacks.concat(old_names - new_names)
      added_stacks.concat(new_names - old_names)
      (new_names & old_names).each do |candidate|
        upgraded_stacks << candidate if stack_upgraded?(candidate)
      end

      removed_stacks.each do |removed_stack|
        removed_services.concat(
          old_data.stack(removed_stack).service_names.map { |name| "#{removed_stack}/#{name}"}
        )
      end

      added_stacks.each do |added_stack|
        added_services.concat(
          new_data.stack(added_stack).service_names.map { |name| "#{added_stack}/#{name}"}
        )
      end

      upgraded_stacks.each do |upgraded_stack|
        old_stack = old_data.stack(upgraded_stack).stack_name
        new_stack = new_data.stack(upgraded_stack).stack_name

        unless old_stack == new_stack
          replaced_stacks[upgraded_stack] = { from: old_stack, to: new_stack }
        end

        old_services = old_data.stack(upgraded_stack).service_names.map { |name| "#{upgraded_stack}/#{name}" }
        new_services = new_data.stack(upgraded_stack).service_names.map { |name| "#{upgraded_stack}/#{name}" }

        removed_services.concat(old_services - new_services)
        added_services.concat(new_services - old_services)
        upgraded_services.concat(new_services & old_services)
      end