blob: 2057e15cf64f2f6c30adf9ac033821e6e36c448f [file] [log] [blame]
Brian Silverman1fc17c02013-12-10 12:57:47 -08001#!/usr/bin/env ruby
2
3# This generates something designed to be copied into Mouser's BOM creation
4# copy/paste box. It turns out that it's usually easier to just manually add
5# everything to your cart with the "EZBuy" thingie, but it's still a reasonable
6# format.
7#
8# Usage: generate_mouser_bom.rb FILE [COPIES]
9
10lines = File.open(ARGV[0]) do |f|
11 lines = f.readlines
12 lines.shift
13 lines.collect do |line|
14 line.split(', ')
15 end
16end
17
18$parts = {}
19
20def print_part(pn_string)
Brian Silverman1fc17c02013-12-10 12:57:47 -080021 pn = pn_string.intern
22 if $parts[pn]
23 $parts[pn] = $parts[pn] + 1
24 else
25 $parts[pn] = 1
26 end
27end
28
29lines.each do |line|
30 pn = line[4]
31 if pn.index(';')
32 parts = pn.split('; ')
33 parts.each do |part_string|
34 part = part_string.match(/(.+) x([0-9]+)?/)
35 if part
36 name = part[1]
37 number = part[2]
38 number.to_i.times do
39 print_part name
40 end
41 else
42 print_part part_string
43 end
44 end
45 else
46 print_part pn unless pn.empty?
47 end
48end
49
50times = (ARGV[1] || 1).to_i
51$parts.each do |pn, number|
52 puts "#{pn}|#{number * times}"
53end