class Circuitdata::Product

Constants

BASE_PATH
BASIC_PRODUCT_STRUCTURE

Attributes

id[RW]

Public Class Methods

from_data(data) click to toggle source
# 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
new(id:, data:) click to toggle source
# File lib/circuitdata/product.rb, line 25
def initialize(id:, data:)
  @id = id
  @data = data
end

Public Instance Methods

data() click to toggle source
# File lib/circuitdata/product.rb, line 61
def data
  @data ||= setup_basic_data
end
data=(new_data) click to toggle source
# File lib/circuitdata/product.rb, line 57
def data=(new_data)
  @data = new_data
end
final_finish_total_area() click to toggle source
# File lib/circuitdata/product.rb, line 93
def final_finish_total_area
  exposed_area.final_finish_total_area
end
layer_name(uuid) click to toggle source
# File lib/circuitdata/product.rb, line 101
def layer_name(uuid)
  layers.find { |l| l[:uuid] == uuid }&.fetch(:name, nil)
end
layers() click to toggle source
# File lib/circuitdata/product.rb, line 77
def layers
  product_data.fetch(:layers, [])
end
materials_data() click to toggle source
# File lib/circuitdata/product.rb, line 49
def materials_data
  data.dig(*materials_data_path)
end
materials_data=(new_data) click to toggle source
# File lib/circuitdata/product.rb, line 53
def materials_data=(new_data)
  Bury.bury(data, *materials_data_path, new_data)
end
metrics() click to toggle source
# File lib/circuitdata/product.rb, line 89
def metrics
  product_data.fetch(:metrics, {})
end
processes() click to toggle source
# File lib/circuitdata/product.rb, line 81
def processes
  product_data.fetch(:processes, [])
end
product_data() click to toggle source
# File lib/circuitdata/product.rb, line 40
def product_data
  data.dig(*product_data_path)
end
product_data=(new_data) click to toggle source
# 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() click to toggle source
# File lib/circuitdata/product.rb, line 97
def product_data_path
  [:open_trade_transfer_package, :products, id.to_sym, :circuitdata]
end
question_answer(path) click to toggle source
# 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() click to toggle source
# File lib/circuitdata/product.rb, line 85
def sections
  product_data.fetch(:sections, [])
end
set_question_answer(*path, value) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

exposed_area() click to toggle source
# File lib/circuitdata/product.rb, line 107
def exposed_area
  @exposed_area ||= ExposedArea.new(self)
end
materials_data_path() click to toggle source
# File lib/circuitdata/product.rb, line 111
def materials_data_path
  [:open_trade_transfer_package, :custom, :materials, :circuitdata]
end
setup_basic_data() click to toggle source
# File lib/circuitdata/product.rb, line 115
def setup_basic_data
  new_data = BASIC_PRODUCT_STRUCTURE.deep_dup
  new_data.dig(:open_trade_transfer_package, :products)[id.to_sym] = {
    circuitdata: {
      version: SCHEMA_VERSION,
    },
  }
  new_data
end