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
60
61
62
63
64
|
# File 'lib/netlinx/workspace/yaml.rb', line 9
def self.parse string
yaml = ::YAML.load string
yaml_systems = yaml['systems']
workspace = NetLinx::Workspace.new
if yaml_systems
workspace.name = yaml_systems.first['name']
project = NetLinx::Project.new name: yaml_systems.first['name']
workspace << project
parse_systems project, yaml_systems
else
workspace.name = yaml['name'] if yaml['name']
workspace.description = yaml['description'] if yaml['description']
yaml_projects = yaml['projects']
yaml_projects.each do |yaml_project|
workspace << NetLinx::Project.new.tap do |project|
project.name = yaml_project['name'] if yaml_project['name']
project.designer = yaml_project['designer'].to_s if yaml_project['designer']
project.dealer = yaml_project['dealer'].to_s if yaml_project['dealer']
project.sales_order = yaml_project['sales_order'].to_s if yaml_project['sales_order']
project.purchase_order = yaml_project['purchase_order'].to_s if yaml_project['purchase_order']
project.description = yaml_project['description'] if yaml_project['description']
parse_systems project, yaml_project['systems']
end
end
end
workspace.file = "#{workspace.name}.apw"
a_system_is_active = false
workspace.projects.each do |project|
project.systems.each do |system|
if a_system_is_active
system.active = false
next
else
a_system_is_active = true if system.active
end
end
end
workspace.projects.first.systems.first.active = true \
unless a_system_is_active \
or workspace.projects.empty? \
or workspace.projects.first.systems.empty?
workspace
end
|