Class: UsdaNutrientDatabase::Import::Foods

Inherits:
Base
  • Object
show all
Defined in:
lib/usda_nutrient_database/import/foods.rb

Instance Attribute Summary

Attributes inherited from Base

#directory

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from UsdaNutrientDatabase::Import::Base

Instance Method Details

#importObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/usda_nutrient_database/import/foods.rb', line 6

def import
  UsdaNutrientDatabase.log 'Importing foods'
  CSV.open("#{directory}/FOOD_DES.txt", 'r:iso-8859-1:utf-8', csv_options) do |csv|
    csv.each do |row|
      UsdaNutrientDatabase::Food.create!(
        nutrient_databank_number: row[0],
        food_group_code: row[1],
        long_description: row[2],
        short_description: row[3],
        common_names: row[4],
        manufacturer_name: row[5],
        survey: row[6],
        refuse_description: row[7],
        percentage_refuse: row[8],
        nitrogen_factor: row[9],
        protein_factor: row[10],
        fat_factor: row[11],
        carbohydrate_factor: row[12]
      )
    end
  end
end