-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTable.rb
More file actions
48 lines (39 loc) · 894 Bytes
/
DataTable.rb
File metadata and controls
48 lines (39 loc) · 894 Bytes
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
load "DataRow.rb"
class DataTable
def initialize
@table = Array.new
end
def add_row name:, value_one:, value_two:
@table << DataRow.new(name: name, value_one: value_one.to_i, value_two: value_two.to_i)
end
def empty?
@table.empty?
end
def minimum_difference
unless @table.nil?
min_difference = Array.new
min_difference << @table[0]
begining = true
@table.each do |row|
if min_difference[0].difference > row.difference
min_difference.clear
min_difference << row
elsif min_difference[0].difference == row.difference
min_difference << row
end
if begining
min_difference.pop
begining = false
end
end
min_difference
end
end
def to_s
out = ""
@table.each do |row|
out += row.to_s + "\n"
end
out
end
end