Class: Circuitdata::Product
- Inherits:
-
Object
- Object
- Circuitdata::Product
- Defined in:
- lib/circuitdata/product.rb
Constant Summary collapse
- BASIC_PRODUCT_STRUCTURE =
{ open_trade_transfer_package: { version: SCHEMA_VERSION, products: {}, custom: { materials: { circuitdata: {}, }, }, }, }
- BASE_PATH =
[:open_trade_transfer_package, :products]
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #data=(new_data) ⇒ Object
- #final_finish_total_area ⇒ Object
-
#initialize(id:, data:) ⇒ Product
constructor
A new instance of Product.
- #layer_name(uuid) ⇒ Object
- #layers ⇒ Object
- #materials_data ⇒ Object
- #materials_data=(new_data) ⇒ Object
- #metrics ⇒ Object
- #processes ⇒ Object
- #product_data ⇒ Object
- #product_data=(new_data) ⇒ Object
- #product_data_path ⇒ Object
- #question_answer(path) ⇒ Object
- #sections ⇒ Object
- #set_question_answer(*path, value) ⇒ Object
- #update_id(new_id) ⇒ Object
Constructor Details
#initialize(id:, data:) ⇒ Product
Returns a new instance of Product.
25 26 27 28 |
# File 'lib/circuitdata/product.rb', line 25 def initialize(id:, data:) @id = id @data = data end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
15 16 17 |
# File 'lib/circuitdata/product.rb', line 15 def id @id end |
Class Method Details
.from_data(data) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/circuitdata/product.rb', line 17 def self.from_data(data) products_hash = data.dig(*BASE_PATH) return [] if products_hash.nil? products_hash.keys.map do |k| self.new(id: k, data: data) end end |
Instance Method Details
#data ⇒ Object
61 62 63 |
# File 'lib/circuitdata/product.rb', line 61 def data @data ||= setup_basic_data end |
#data=(new_data) ⇒ Object
57 58 59 |
# File 'lib/circuitdata/product.rb', line 57 def data=(new_data) @data = new_data end |
#final_finish_total_area ⇒ Object
93 94 95 |
# File 'lib/circuitdata/product.rb', line 93 def final_finish_total_area exposed_area.final_finish_total_area end |
#layer_name(uuid) ⇒ Object
101 102 103 |
# File 'lib/circuitdata/product.rb', line 101 def layer_name(uuid) layers.find { |l| l[:uuid] == uuid }&.fetch(:name, nil) end |
#layers ⇒ Object
77 78 79 |
# File 'lib/circuitdata/product.rb', line 77 def layers product_data.fetch(:layers, []) end |
#materials_data ⇒ Object
49 50 51 |
# File 'lib/circuitdata/product.rb', line 49 def materials_data data.dig(*materials_data_path) end |
#materials_data=(new_data) ⇒ Object
53 54 55 |
# File 'lib/circuitdata/product.rb', line 53 def materials_data=(new_data) Bury.bury(data, *materials_data_path, new_data) end |
#metrics ⇒ Object
89 90 91 |
# File 'lib/circuitdata/product.rb', line 89 def metrics product_data.fetch(:metrics, {}) end |
#processes ⇒ Object
81 82 83 |
# File 'lib/circuitdata/product.rb', line 81 def processes product_data.fetch(:processes, []) end |
#product_data ⇒ Object
40 41 42 |
# File 'lib/circuitdata/product.rb', line 40 def product_data data.dig(*product_data_path) end |
#product_data=(new_data) ⇒ Object
44 45 46 47 |
# File 'lib/circuitdata/product.rb', line 44 def product_data=(new_data) Bury.bury(data, *product_data_path, new_data) product_data.merge!(version: SCHEMA_VERSION) end |
#product_data_path ⇒ Object
97 98 99 |
# File 'lib/circuitdata/product.rb', line 97 def product_data_path [:open_trade_transfer_package, :products, id.to_sym, :circuitdata] end |
#question_answer(path) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/circuitdata/product.rb', line 65 def question_answer(path) return nil if path.empty? path = path.map { |p| p.is_a?(String) ? p.to_sym : p } value = Bury.dig(product_data, *path) value end |
#sections ⇒ Object
85 86 87 |
# File 'lib/circuitdata/product.rb', line 85 def sections product_data.fetch(:sections, []) end |
#set_question_answer(*path, value) ⇒ Object
72 73 74 75 |
# File 'lib/circuitdata/product.rb', line 72 def set_question_answer(*path, value) return if value.nil? && question_answer(path).nil? Bury.bury(product_data, *path, value) end |
#update_id(new_id) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/circuitdata/product.rb', line 30 def update_id(new_id) product_map = data.dig(*BASE_PATH) current_data = product_data product_map.delete(id.to_sym) product_map[new_id.to_sym] = { circuitdata: current_data, } @id = new_id end |