frozen-swap #24

Open
bustikiller wants to merge 5 commits from frozen-swap into main
2 changed files with 10 additions and 13 deletions
Showing only changes of commit 1d28cfc527 - Show all commits

View File

@ -17,9 +17,7 @@ module Tables
end end
def discomfort def discomfort
@tables.map do |table| @tables.map(&:discomfort).sum
local_discomfort(table)
end.sum
end end
def inspect def inspect
@ -28,7 +26,7 @@ module Tables
def pretty_print def pretty_print
@tables.map.with_index do |table, i| @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.join("\n")
end end
@ -55,11 +53,5 @@ module Tables
arrangement.update!(discomfort:) arrangement.update!(discomfort:)
end end
end end
private
def local_discomfort(table)
table.discomfort ||= DiscomfortCalculator.new(table).calculate
end
end end
end end

View File

@ -1,15 +1,20 @@
module Tables module Tables
class Table < Array class Table < Array
attr_accessor :discomfort attr_writer :discomfort
def initialize(*args) def initialize(*args)
super super
reset reset
end end
def reset def reset
original_discomfort = discomfort original_discomfort = @discomfort
@discomfort = nil @discomfort = nil
original_discomfort original_discomfort
end end
def discomfort
@discomfort ||= DiscomfortCalculator.new(self).calculate
end
end end
end end