-
Notifications
You must be signed in to change notification settings - Fork 1
/
bagnowin.rb
41 lines (39 loc) · 1.12 KB
/
bagnowin.rb
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
require 'component'
class BagNoWin
attr_accessor :id, :positions
attr_reader :components, :selectedComponents, :has_selected
def initialize(id = nil)
@id = id
@positions = {}
@selectedComponents = []
@has_selected = false
end
def components=(components)
@components = components
@positions ||= {}
@positions.clear()
@components.each do | comp |
comp.positions.each do | compPos |
@positions[compPos.downcase().split("-")[0].split("x")[0]] ||= []
@positions[compPos.downcase().split("-")[0].split("x")[0]] << comp
end
end
end
def clearSelection()
if (@selectedComponents.size > 0)
@selectedComponents.clear()
end
@has_selected = false
end
def selectPosition(position)
if (@positions[position.downcase().split("-")[0].split("x")[0]])
@positions[position.downcase().split("-")[0].split("x")[0]].each do | component |
unless @selectedComponents.include?(component)
@selectedComponents << component
# debug "Found component for #{position}"
end
end
@has_selected = true
end
end
end