-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgroup.rb
More file actions
59 lines (48 loc) · 1.24 KB
/
group.rb
File metadata and controls
59 lines (48 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require_relative "methods"
class Group
attr_reader :name, :names_array
def initialize(group_name, file_path)
@name = group_name
@path = file_path
@names_array = self.path_to_array
end
def randomise_order
@names_array.shuffle
end
def output_random_array
#TODO FIX CAPITALISATION BUG
randomise_order.each_with_index do |name, index|
puts "#{index +1}. #{name}".colorize(select_random_color)
sleep(0.5)
end
puts "\n"
puts "\n"
end
def add_name(name)
@names_array.push(name)
end
def path_to_array
begin
array = File.readlines(get_file_path).map {|name| name.strip}
rescue
puts "Invalid path, creating file"
File.open(get_file_path, "w") do |file|
file.write("")
end
array = []
end
return array
end
def save
File.open(@path, "w+") do |file|
file.puts(@names_array)
end
end
private
def get_file_path
@path
end
end
# test_group = Group.new("test group", "./groups/test-group.txt")
# test_group.add_name("Bob Smith")
# test_group.save