swap-candidates #26
@ -17,9 +17,7 @@ module Tables
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def discomfort
 | 
			
		||||
      @tables.map do |table|
 | 
			
		||||
        local_discomfort(table)
 | 
			
		||||
      end.sum
 | 
			
		||||
      @tables.map(&:discomfort).sum
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def inspect
 | 
			
		||||
@ -28,7 +26,7 @@ module Tables
 | 
			
		||||
 | 
			
		||||
    def pretty_print
 | 
			
		||||
      @tables.map.with_index do |table, i|
 | 
			
		||||
        "Table #{i + 1} (#{table.count} ppl): (#{local_discomfort(table)}) #{table.map(&:full_name).join(', ')}"
 | 
			
		||||
        "Table #{i + 1} (#{table.count} ppl): (#{table.discomfort}) #{table.map(&:full_name).join(', ')}"
 | 
			
		||||
      end.join("\n")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -55,11 +53,5 @@ module Tables
 | 
			
		||||
        arrangement.update!(discomfort:)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    def local_discomfort(table)
 | 
			
		||||
      table.discomfort ||= DiscomfortCalculator.new(table).calculate
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1,15 +1,20 @@
 | 
			
		||||
module Tables
 | 
			
		||||
  class Table < Array
 | 
			
		||||
    attr_accessor :discomfort
 | 
			
		||||
    attr_writer :discomfort
 | 
			
		||||
 | 
			
		||||
    def initialize(*args)
 | 
			
		||||
      super
 | 
			
		||||
      reset
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def reset
 | 
			
		||||
      original_discomfort = discomfort
 | 
			
		||||
      original_discomfort = @discomfort
 | 
			
		||||
      @discomfort = nil
 | 
			
		||||
      original_discomfort
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def discomfort
 | 
			
		||||
      @discomfort ||= DiscomfortCalculator.new(self).calculate
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user