Sha256: 543f1231c5c68fdf5e20c5bedc2dcad7601ff65f52ecabe965aefd101d8bfe82

Contents?: true

Size: 989 Bytes

Versions: 6

Compression:

Stored size: 989 Bytes

Contents

module UsdaNutrientDatabase
  module Import
    class FoodsNutrients < Base
      def import
        UsdaNutrientDatabase.log 'Importing foods_nutrients'
        CSV.open(
          "#{directory}/NUT_DATA.txt", 'r:iso-8859-1:utf-8', csv_options
        ) do |csv|
          csv.each { |row| extract_row(row) }
        end
      end

      private

      def columns
        [
          :nutrient_databank_number, :nutrient_number, :nutrient_value,
          :num_data_points, :standard_error, :src_code, :derivation_code,
          :ref_nutrient_databank_number, :add_nutrient_mark, :num_studies, :min,
          :max, :degrees_of_freedom, :lower_error_bound, :upper_error_bound,
          :statistical_comments, :add_mod_date
        ]
      end

      def extract_row(row)
        attrs = {}
        columns.each_with_index do |column, index|
          attrs.merge!(column => row[index])
        end
        UsdaNutrientDatabase::FoodsNutrient.create!(attrs)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
usda-nutrient-database-0.4.0 lib/usda_nutrient_database/import/foods_nutrients.rb
usda-nutrient-database-0.3.0 lib/usda_nutrient_database/import/foods_nutrients.rb
usda-nutrient-database-0.2.0 lib/usda_nutrient_database/import/foods_nutrients.rb
usda-nutrient-database-0.1.2 lib/usda_nutrient_database/import/foods_nutrients.rb
usda-nutrient-database-0.1.1 lib/usda_nutrient_database/import/foods_nutrients.rb
usda-nutrient-database-0.1.0 lib/usda_nutrient_database/import/foods_nutrients.rb