Created
March 13, 2012 18:36
-
-
Save tdouce/2030559 to your computer and use it in GitHub Desktop.
Retrieve distance from project location to product manufacturers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get all lookup_keys for a product | |
?> project2.project_items[1].product.product_features.map {|pf| [pf.product_feature_type.lookup_key, pf.product_feature_type.description] } | |
# pretty print | |
?> project2.project_items[1].product.product_features.map {|pf| puts [pf.product_feature_type.lookup_key, pf.product_feature_type.description].inspect } | |
# Longhand lookup_key for a product | |
?> project2.project_items[1].product.product_features.map {|pf| [pf.product_feature_type.lookup_key, pf.product_feature_type.description] if pf.product_feature_type.lookup_key == 'l_m' }.compact | |
# Get all manufacturing locations for a product using convince method | |
?> manu_locations = project2.project_items[1].product.product_features_for_type("l_m") => [#<ProductFeature id: 1837, product_feature_type_id: 19, product_id: 67, text_data: "48117", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1838, product_feature_type_id: 19, product_id: 67, text_data: "75109", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1839, product_feature_type_id: 19, product_id: 67, text_data: "52742", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1840, product_feature_type_id: 19, product_id: 67, text_data: "15025", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1841, product_feature_type_id: 19, product_id: 67, text_data: "14456", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1842, product_feature_type_id: 19, product_id: 67, text_data: "93631", numeric_data: nil, position: 0, query: nil, boolean_data: nil>, #<ProductFeature id: 1843, product_feature_type_id: 19, product_id: 67, text_data: "29729", numeric_data: nil, position: 0, query: nil, boolean_data: nil>] | |
# Get the distance from project location (postal code) to each manufacturing location(postal code) | |
?> manu_locations_less_500 = manu_locations.map {|mu| project2.distance_from( PostalCode.find_by_postal_cd(mu.text_data)).to('mi') if project2.distance_from( PostalCode.find_by_postal_cd(mu.text_data)) <= '500 miles'.unit }.compact | |
=> [479.168 mi, 148.167 mi] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment