Class: UsdaNutrientDatabase::Import::Nutrients

Inherits:
Base
  • Object
show all
Defined in:
lib/usda_nutrient_database/import/nutrients.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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/usda_nutrient_database/import/nutrients.rb', line 4

def import
  UsdaNutrientDatabase.log 'Importing nutrients'
  CSV.open(
    "#{directory}/NUTR_DEF.txt", 'r:iso-8859-1:utf-8', csv_options
  ) do |csv|
    csv.each do |row|
      UsdaNutrientDatabase::Nutrient.create!(
        nutrient_number: row[0], units: row[1], tagname: row[2],
        nutrient_description: row[3], number_decimal_places: row[4],
        sort_record_order: row[5]
      )
    end
  end
end