Skip to content

Instantly share code, notes, and snippets.

@asonas
Created September 10, 2013 17:07
Show Gist options
  • Save asonas/6512441 to your computer and use it in GitHub Desktop.
Save asonas/6512441 to your computer and use it in GitHub Desktop.
class Arranger
def initialize(capacity, file_path)
@capacity = capacity
@members = parse_members_text(file_path)
@members.shuffle!
end
def decision
@members.first(@capacity)
end
def next_decision
@members.last(@members.length - @capacity)
end
private
def parse_members_text(file_path)
text = File.read(file_path, encoding: Encoding::UTF_8)
text.rstrip.split(/\r?\n/).map { |line| line.chomp }
end
end
snorkel_driver = Arranger.new(6, "snorkel_members.txt")
puts "---First car members---"
puts snorkel_driver.decision
puts "---Second car members---"
puts snorkel_driver.next_decision
glassboat_driver = Arranger.new(6, "glassboat_members.txt")
puts "---First car members---"
puts glassboat_driver.decision
puts "---Second car members---"
puts glassboat_driver.next_decision
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment