Sha256: 81bb4a96d86fb29796c281afa9af57be11f70b2d94d6aa09adbe6baf6b08f0d9

Contents?: true

Size: 874 Bytes

Versions: 7

Compression:

Stored size: 874 Bytes

Contents

# encoding: utf-8

module UsdaNutrientDatabase
  module Import
    class Foods < Base

      private

      def extract_row(row)
        build_food(row).save
      end

      def build_food(row)
        UsdaNutrientDatabase::Food.new.tap do |food|
          columns.each_with_index do |column, index|
            food.send("#{column}=", row[index])
          end
        end
      end

      def log_import_started
        UsdaNutrientDatabase.log 'Importing foods'
      end

      def filename
        'FOOD_DES.txt'
      end

      def columns
        [
          :nutrient_databank_number, :food_group_code, :long_description,
          :short_description, :common_names, :manufacturer_name, :survey,
          :refuse_description, :percentage_refuse, :nitrogen_factor,
          :protein_factor, :fat_factor, :carbohydrate_factor
        ]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
usda-nutrient-database-1.0.1 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-1.0.0 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-0.8.1 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-0.8.0 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-0.7.0 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-0.6.0 lib/usda_nutrient_database/import/foods.rb
usda-nutrient-database-0.5.0 lib/usda_nutrient_database/import/foods.rb