Class: Kut::NetList2Bom
- Inherits:
-
Object
- Object
- Kut::NetList2Bom
- Defined in:
- lib/kut/commands/net_list2bom.rb
Instance Attribute Summary collapse
-
#help_banner ⇒ Object
readonly
Returns the value of attribute help_banner.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #help(args) ⇒ Object
-
#initialize ⇒ NetList2Bom
constructor
A new instance of NetList2Bom.
- #net2bom(f_in, f_out) ⇒ Object
- #run(args) ⇒ Object
Constructor Details
#initialize ⇒ NetList2Bom
Returns a new instance of NetList2Bom.
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 |
# File 'lib/kut/commands/net_list2bom.rb', line 10 def initialize @name = 'net2bom' @help_banner = 'Generatr bill of materials from netlist' @generators = [] @options = OpenStruct.new @options.in_file_name = '-' @options.out_file_name = '-' @options.net_list_loader = Kut::NetList::KiCadNetList @options.separator = ';' @option_parser = OptionParser.new do |opts| opts. = "Usage: kut #{self.name} [options]" opts.on("-f", "--format NET_LIST_FORMAT", "Netlist file format (kicad - default, pcad)") do |format| case format when 'pcad' then @options.net_list_loader = Kut::NetList::PCadNetList when 'kicad' then @options.net_list_loader = Kut::NetList::KiCadNetList else $stderr << "Netlist format #{format} isn't supported.\n" exit end end opts.on("-i", "--input INPUT_FILE", "Innput pins file. if - to use stdin.") do |file_name| @options.in_file_name = file_name end opts.on("-o", "--output OUTPUT_FILE", "Output libary file. if - to use stdout.") do |file_name| @options.out_file_name = file_name end end end |
Instance Attribute Details
#help_banner ⇒ Object (readonly)
Returns the value of attribute help_banner.
8 9 10 |
# File 'lib/kut/commands/net_list2bom.rb', line 8 def @help_banner end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/kut/commands/net_list2bom.rb', line 7 def name @name end |
Instance Method Details
#help(args) ⇒ Object
46 47 48 49 |
# File 'lib/kut/commands/net_list2bom.rb', line 46 def help(args) @option_parser.parse!(args) @option_parser.to_s() end |
#net2bom(f_in, f_out) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kut/commands/net_list2bom.rb', line 51 def net2bom(f_in, f_out) net_list = @options.net_list_loader.new(f_in) cmp_list = net_list.by_components() sep = @options.separator f_out << "ref#{sep}value#{sep}footprint\n" cmp_list.each{ |cmp| f_out << "#{cmp.reference}#{sep}#{cmp.value}#{sep}#{cmp.footprint}\n" } end |
#run(args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kut/commands/net_list2bom.rb', line 64 def run(args) begin @option_parser.parse!(args) rescue OptionParser::InvalidOption => e $stderr << "Unknow option #{e}\n" exit end f_in = $stdin f_in = File.new(@options.in_file_name) if @options.in_file_name && @options.in_file_name != '-' f_out = $stdout f_out = File.new(@options.out_file_name, 'w') if @options.out_file_name && @options.out_file_name != '-' net2bom(f_in, f_out) end |