Sha256: d9e8f9648877a27103c785058588aac144f2f38616d455c72ff1ec49ce52d1d1

Contents?: true

Size: 813 Bytes

Versions: 7

Compression:

Stored size: 813 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
      importer_names.each { |importer_name| importer_for(importer_name).import }
    ensure
      downloader.cleanup
    end

    private

    def importer_names
      [
        'Foods', 'Nutrients', 'FoodsNutrients', 'FoodGroups', 'Weights',
        'Footnotes', 'SourceCodes'
      ]
    end

    def importer_for(importer_name)
      "UsdaNutrientDatabase::Import::#{importer_name}".constantize.
        new("#{directory}/#{version}")
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
usda-nutrient-database-1.3.0 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-1.2.0 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-1.1.0 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-1.0.1 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-1.0.0 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-0.8.1 lib/usda_nutrient_database/importer.rb
usda-nutrient-database-0.8.0 lib/usda_nutrient_database/importer.rb