Sha256: 737715c952a58455b3a081c93f8fa8eb31757572beb08ca56bc7072873ef9ad0

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

module UsdaNutrientDatabase
  class Importer
    attr_reader :directory, :version

    def initialize(directory = 'tmp/usda', version = 'sr25')
      @directory = directory
      @version = version
    end

    def import
      downloader.download_and_unzip
      food_group_importer.import
      food_importer.import
      nutrient_importer.import
      foods_nutrient_importer.import
    ensure
      downloader.cleanup
    end

    private

    def food_importer
      UsdaNutrientDatabase::Import::Foods.new("#{directory}/#{version}")
    end

    def nutrient_importer
      UsdaNutrientDatabase::Import::Nutrients.new("#{directory}/#{version}")
    end

    def foods_nutrient_importer
      UsdaNutrientDatabase::Import::FoodsNutrients.
        new("#{directory}/#{version}")
    end

    def food_group_importer
      UsdaNutrientDatabase::Import::FoodGroups.new("#{directory}/#{version}")
    end

    def downloader
      UsdaNutrientDatabase::Import::Downloader.new(directory, version)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usda-nutrient-database-0.1.2 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-0.1.1 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-0.1.0 lib/usda_nutrient_database/importer.rb