Class: SolidRuby::BillOfMaterial::BillOfMaterial
- Inherits:
-
Object
- Object
- SolidRuby::BillOfMaterial::BillOfMaterial
- Defined in:
- lib/solidruby/bill_of_material.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
- #add(part, quantity = 1) ⇒ Object
-
#initialize ⇒ BillOfMaterial
constructor
A new instance of BillOfMaterial.
- #output ⇒ Object
- #save(filename = 'output/bom.txt') ⇒ Object
Constructor Details
#initialize ⇒ BillOfMaterial
Returns a new instance of BillOfMaterial.
19 20 21 |
# File 'lib/solidruby/bill_of_material.rb', line 19 def initialize @parts = {} end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
18 19 20 |
# File 'lib/solidruby/bill_of_material.rb', line 18 def parts @parts end |
Instance Method Details
#add(part, quantity = 1) ⇒ Object
23 24 25 26 |
# File 'lib/solidruby/bill_of_material.rb', line 23 def add(part, quantity = 1) @parts[part] ||= 0 @parts[part] += quantity end |
#output ⇒ Object
28 29 30 |
# File 'lib/solidruby/bill_of_material.rb', line 28 def output @parts.map { |key, qty| "#{qty} x #{key}" }.join("\n") end |
#save(filename = 'output/bom.txt') ⇒ Object
32 33 34 35 36 |
# File 'lib/solidruby/bill_of_material.rb', line 32 def save(filename = 'output/bom.txt') file = File.open(filename, 'w') file.puts output file.close end |