usda-nutrient-database 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cebda7a2b5846d466d3044269890e741582222b1
4
- data.tar.gz: 3590220700d4755fed490d98e55d6247ec2c99d3
3
+ metadata.gz: 7b5a0b3447d833e6c29476c14ec6412732351f22
4
+ data.tar.gz: 3e08d047a6997358351a37f17181bd7552fa0c37
5
5
  SHA512:
6
- metadata.gz: ab9b71ae50a77af706f1aad9da7293daa34060bade288d11820662f2c758c410d07806346fd590a13f9eab43e00c8d3ada8de9833a1a9e94cdf398180134c3d0
7
- data.tar.gz: 388b9e1e6b72fab432c8b51f6f0e5973a7cf062f036d4e081c7079afc140a4aa620aae6b9589c8d9bd6e7f05a53cc46504573c272013284f581d1f0404cd5faf
6
+ metadata.gz: 899ea32be0548efc1a3102c465eb1493604512e515f8dc38f169ea9bde12599940d09766bcee3f9648c7ee250135a91908284130c7805a183134ad4e2e6663e9
7
+ data.tar.gz: d9ffd8fb8cca6e0079e88dc667bd780c9aa691852fdd943036bf981feb9a6d63e5f46dc70334ab1adcf64b8303ada07b32c8cf5b48eb7300c0feef56c335502c
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # Usda::Nutrient::Database
1
+ # USDA Nutrient Database
2
2
 
3
- TODO: Write a gem description
3
+ The USDA nutrition database is a great source of nutrition information. However,
4
+ the data formatting options (plain text ASCII files or MS-Access) leave a little
5
+ to be desired.
6
+
7
+ This is a simple gem to import the database into your ruby application.
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,9 +20,26 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install usda-nutrient-database
18
22
 
23
+ If you're using rails then copy the migrations across:
24
+ ```
25
+ rake usda_nutrient_database_engine:install:migrations
26
+ ```
27
+
19
28
  ## Usage
20
29
 
21
- TODO: Write usage instructions here
30
+ Import the latest data with the import task:
31
+ ```
32
+ rake usda:import
33
+ ```
34
+ This is going to take a while. 20+ minutes on my 2.66 GHz i7 macbook pro
35
+
36
+ Use the models to query and profit:
37
+ ```
38
+ UsdaNutrientDatabase::FoodGroup
39
+ UsdaNutrientDatabase::Food
40
+ UsedNutrientDatabase::Nutrient
41
+ UsdaNutrientDatabase::FoodsNutrient
42
+ ```
22
43
 
23
44
  ## Contributing
24
45
 
@@ -1,6 +1,6 @@
1
1
  class CreateUsdaFoodGroups < ActiveRecord::Migration
2
2
  def change
3
- create_table :usda_food_groups, id: :code do |t|
3
+ create_table :usda_food_groups, id: false, primary_key: :code do |t|
4
4
  t.string :code, null: false, index: true, uniq: true
5
5
  t.string :description, null: false
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class CreateUsdaNutrients < ActiveRecord::Migration
2
2
  def change
3
- create_table :nutrients, id: :nutrient_number do |t|
3
+ create_table :usda_nutrients, id: false, primary_key: :nutrient_number do |t|
4
4
  t.string :nutrient_number, null: false, index: true
5
5
  t.string :units, null: false
6
6
  t.string :tagname
@@ -1,6 +1,6 @@
1
1
  namespace :usda do
2
2
  desc 'Import the latest USDA nutrition data'
3
3
  task import: :environment do
4
- UsdaNutrientDatabase::Importer.new
4
+ UsdaNutrientDatabase::Importer.new('tmp/usda', 'sr25').import
5
5
  end
6
6
  end
@@ -1,5 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'usda_nutrient_database/configuration'
3
+ require 'usda_nutrient_database/engine' if defined?(Rails)
3
4
  require 'usda_nutrient_database/food_group'
4
5
  require 'usda_nutrient_database/food'
5
6
  require 'usda_nutrient_database/nutrient'
@@ -0,0 +1,6 @@
1
+ require 'rails/engine'
2
+
3
+ module UsdaNutrientDatabase
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -1,6 +1,7 @@
1
1
  module UsdaNutrientDatabase
2
2
  class Nutrient < ActiveRecord::Base
3
3
  self.table_name = 'usda_nutrients'
4
+ self.primary_key = 'nutrient_number'
4
5
 
5
6
  validates :nutrient_number, presence: true,
6
7
  uniqueness: { allow_blank: true }
@@ -1,3 +1,3 @@
1
1
  module UsdaNutrientDatabase
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usda-nutrient-database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Beedle
@@ -199,6 +199,7 @@ files:
199
199
  - lib/tasks/usda_nutrient_database.rake
200
200
  - lib/usda-nutrient-database.rb
201
201
  - lib/usda_nutrient_database/configuration.rb
202
+ - lib/usda_nutrient_database/engine.rb
202
203
  - lib/usda_nutrient_database/food.rb
203
204
  - lib/usda_nutrient_database/food_group.rb
204
205
  - lib/usda_nutrient_database/foods_nutrient.rb