Skip to content

Instantly share code, notes, and snippets.

@tdouce
Created February 29, 2012 21:05
Show Gist options
  • Save tdouce/1944339 to your computer and use it in GitHub Desktop.
Save tdouce/1944339 to your computer and use it in GitHub Desktop.
Not sure why 'MR Credit 5 Regional Materials' isn't show up
From console:
?> project
=> #<Project id: 1, user_id: 1, publisher_id: 2, name: "Travis_test_1", street_address: "407 Greenwood Drive", suite: "", city: "Athens", state: "GA", postal_code: "49508", country: "United States", confidential: false, owner_occupied: false, gross_square_feet: 5000, total_budget: #<BigDecimal:10b745c50,'0.5E5',9(18)>, project_type_id: nil, owner_type_id: nil, occupant_type_id: nil, project_scope_id: nil, project_phase_id: nil, session_id: nil, created_at: "2012-02-28 16:06:46", updated_at: "2012-02-29 13:41:41", saved: true, auto_project_source: true>
>> project.name
=> "Travis_test_1"
>> project.project_items
=> [#<ProjectItem id: 1, project_id: 1, product_id: 29, quantity: 1, unit_price: #<BigDecimal:10b71cff8,'0.75E2',9(18)>, postal_code_of_manufacture: "53551", params: nil, postal_code_of_fabrication: nil>, #<ProjectItem id: 2, project_id: 1, product_id: 16, quantity: 1, unit_price: #<BigDecimal:10b7164a0,'0.1E3',9(18)>, postal_code_of_manufacture: "49456", params: nil, postal_code_of_fabrication: nil>, #<ProjectItem id: 3, project_id: 1, product_id: 17, quantity: 1, unit_price: #<BigDecimal:10b7126e8,'0.2E3',9(18)>, postal_code_of_manufacture: "49508", params: nil, postal_code_of_fabrication: nil>]
>> project.project_items.map {|pi| [pi.product.name, pi.postal_code_of_manufacture]}
=> [["Product 29", "53551"], ["Product 16", "49456"], ["Product 17", "49508"]]
>>
@duien
Copy link

duien commented Feb 29, 2012

To add locations of extraction to Product 17, do this

project = Project.find_by_id(1)
Formula.find_by_lookup_key('PCNT_EXTRACT_PROC_LT_300M').evaluate(project.project_items[2])
#=> 0
# Product has 0% extracted within 300 miles


product = Product.find_by_name('Product 17')
pf = ProductFeature.new('l_e_1_1', '49508')
pf2 = ProductFeature.new('l_e_pcnt_1_1', 0.5)
product.product_features << pf
product.product_features << pf2
product.save

project.reload
Formula.find_by_lookup_key('PCNT_EXTRACT_PROC_LT_300M').evaluate(project.project_items[2]).to_f
#=> 0.5
# Product has 50% extracted within 300 miles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment