Skip to content

Instantly share code, notes, and snippets.

@Insood
Last active Oct 26, 2018
Embed
What would you like to do?
class ERP
def self.flat_bom(part_number)
Rails.cache.fetch("erp_flat_bom_#{part_number}") do
parts = {}
bom = ERP.get_bom(part_number)
bom.items.each do |item|
[... recursively go down to get every part in this indented BOM...]
end
parts
end
end
def self.get_bom(part_number)
[ ... some fancy caching here ...]
end
end
class CreateRouter < ActiveRecord::Migration
def change
create_table :router_component_groups do |t|
t.string :description
t.integer :position
t.string :preface_text
t.string :postface_text
t.string :verb
t.boolean :ignore
t.boolean :immutable
t.boolean :show_image
t.references :step
t.timestamps null: false
end
create_table :router_components do |t|
t.string :part_number
t.string :description
t.integer :position
t.references :component_group
t.timestamps null: false
end
end
end
class CreateSoftwareSpecifications < ActiveRecord::Migration
def change
create_table :software_specifications do |t|
t.string :software_part_number
...
t.string :parameter (x20)
...
t.timestamps
end
add_index :software_specifications, [:software_part_number], unique: true
end
end
class UnitInformation
attr_reader :parts_list, :part_number
def initialize(part_number, parts_list)
@part_number = part_number
@parts_list = parts_list
end
def determine_software_pn
parts_list.keys.find do |pn|
... regexes here ...
end
end
def software_part_number
@_software_part_number ||= determine_software_pn
return @_software_part_number
end
def load_software_specifications
@_software_specifications = SoftwareSpecifications.where(part_number: software_part_number) # Load from DB...
end
def test_parameters
@_software_specifications ||= load_software_specifications
end
def test_parameter_a
return software_specification.test_parameter_a
end
def determine_motor_part_numbers
part_numbers = []
ComponentGroup.where(description: "Motors").each do |group|
group.components.each do |pn, qty|
part_numbers << pn if parts_list.has_key?(pn)
end
end
return part_numbers
end
def motor_part_numbers
@_motor_part_numbers ||= determine_motor_part_number
return @_motor_part_numbers
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment