49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/bcl/component_from_spreadsheet.rb', line 49
def save(save_path, chunk_size = 1000, delete_old_gather = false)
@worksheets.each do |worksheet|
worksheet.components.each do |component|
component_xml = Component.new("#{save_path}/components")
component_xml.name = component.name
component_xml.uid = component.uid
component_xml.add_tag(worksheet.name)
puts "tag: #{worksheet.name}"
values = component.values
puts " headers: #{component.}"
component..each do ||
if /description/i.match?(.name)
name = values.delete_at(0) uid = values.delete_at(0)
component_xml.comp_version_id = values.delete_at(0)
description = values.delete_at(0)
component_xml.modeler_description = values.delete_at(0)
component_xml.description = description
elsif /provenance/i.match?(.name)
author = values.delete_at(0)
datetime = values.delete_at(0)
if datetime.nil?
datetime = DateTime.new
end
= values.delete_at(0)
component_xml.add_provenance(author.to_s, datetime.strftime('%Y-%m-%d'), .to_s)
elsif /tag/i.match?(.name)
value = values.delete_at(0)
component_xml.add_tag(value)
elsif /attribute/i.match?(.name)
value = values.delete_at(0)
name = .children[0]
units = ''
if match_data = /(.*)\((.*)\)/.match(name)
name = match_data[1].strip
units = match_data[2].strip
end
component_xml.add_attribute(name, value, units)
elsif /source/i.match?(.name)
manufacturer = values.delete_at(0)
model = values.delete_at(0)
serial_no = values.delete_at(0)
year = values.delete_at(0)
url = values.delete_at(0)
component_xml.source_manufacturer = manufacturer
component_xml.source_model = model
component_xml.source_serial_no = serial_no
component_xml.source_year = year
component_xml.source_url = url
elsif /file/i.match?(.name)
software_program = values.delete_at(0)
version = values.delete_at(0)
filename = values.delete_at(0)
filetype = values.delete_at(0)
filepath = values.delete_at(0)
next if filename == '' || filename.nil?
unless File.exist?(filepath)
puts "[ComponentFromSpreadsheet] ERROR #{filepath} -> File does not exist, will not be included in component xml"
next end
component_xml.add_file(software_program, version, filepath, filename, filetype)
else
raise "Unknown section #{.name}"
end
end
component_xml.save_tar_gz(false)
end
end
BCL.gather_components(save_path, chunk_size, delete_old_gather)
end
|