Skip to content

Commit

Permalink
PR feedback, trimming class down
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarin committed Oct 13, 2023
1 parent b127e08 commit 7cfed5a
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions bin/cluster_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class ClusterValidator
attr_reader :output_path # file name
def initialize(buffer_max: 500)
@buffer = []
@buffer_max = buffer_max
def initialize
# Make an output file in the right place
ymd = Time.now.strftime("%Y-%m-%d")
dir = Settings.local_report_path
Expand All @@ -19,30 +17,16 @@ def initialize(buffer_max: 500)

def run
puts "Writing to #{output_path}"
@outf = File.open(output_path, "w")
# Go through each cluster and check if valid.
comment "These are ocns of invalid clusters:"
Cluster.each do |c|
unless c.valid?
@buffer << c.ocns.first
end
if @buffer.size > @buffer_max
@outf.puts(@buffer.join("\n"))
@buffer = []
File.open(output_path, "w") do |outf|
# Go through each cluster and check if valid.
outf.puts "# These are ocns of invalid clusters:"
Cluster.each do |c|
unless c.valid?
outf.puts(c.ocns.first)
end
end
outf.puts "# Done"
end
ensure
# Empty bufferfer one last time and be done.
@outf.puts(@buffer.join("\n")) if @buffer.any?
comment "Done"
@outf.close
end

private

# Make a comment in the outfile
def comment(msg)
@outf.puts "# " + msg
end
end

Expand Down

0 comments on commit 7cfed5a

Please sign in to comment.