usda-nutrient-database 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +1 -1
- data/db/migrate/9_add_referential_integrity.rb +82 -0
- data/lib/usda-nutrient-database.rb +4 -0
- data/lib/usda_nutrient_database/configuration.rb +6 -1
- data/lib/usda_nutrient_database/import/base.rb +1 -1
- data/lib/usda_nutrient_database/import/downloader.rb +12 -4
- data/lib/usda_nutrient_database/importer.rb +8 -3
- data/lib/usda_nutrient_database/tasks/usda_nutrient_database.rake +9 -4
- data/lib/usda_nutrient_database/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1e7f2d97c62a659ed44c93cbaf15975196107cd
|
4
|
+
data.tar.gz: 4ce234c30e8b5fc058fdd8960d2fd3dcfe416707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d3104e79ce945684f7550a77f8edada72dc5159460aaaeccc972fdb2c306d4438f275cac30a9906ac75b0b5aa32562bbc68794cec1bcb670c1bad0dd34974e4
|
7
|
+
data.tar.gz: 55c2bc53e7260685b3a6352ad904ca516760afa188c67fc5bdd7d9bb1b0bfee2a7fc71b9bb4b21e89ac444043686f42cec46681dc2a0c2846c1410fa3ef1379c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -64,7 +64,7 @@ Use the models to query and profit:
|
|
64
64
|
```
|
65
65
|
UsdaNutrientDatabase::FoodGroup
|
66
66
|
UsdaNutrientDatabase::Food
|
67
|
-
|
67
|
+
UsdaNutrientDatabase::Nutrient
|
68
68
|
UsdaNutrientDatabase::FoodsNutrient
|
69
69
|
UsdaNutrientDatabase::Weight
|
70
70
|
UsdaNutrientDatabase::SourceCode
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class AddReferentialIntegrity < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
remove_index :usda_nutrients, :nutrient_number
|
4
|
+
add_index :usda_nutrients, :nutrient_number, unique: true
|
5
|
+
|
6
|
+
remove_index :usda_source_codes, :code
|
7
|
+
add_index :usda_source_codes, :code, unique: true
|
8
|
+
|
9
|
+
remove_index :usda_food_groups, :code
|
10
|
+
add_index :usda_food_groups, :code, unique: true
|
11
|
+
|
12
|
+
remove_index :usda_foods, :nutrient_databank_number
|
13
|
+
add_index :usda_foods, :nutrient_databank_number, unique: true
|
14
|
+
|
15
|
+
add_index :usda_foods_nutrients, [
|
16
|
+
:nutrient_databank_number,
|
17
|
+
:nutrient_number
|
18
|
+
],
|
19
|
+
unique: true,
|
20
|
+
name: "index_usda_foods_nutrients_on_databank_number_and_number"
|
21
|
+
|
22
|
+
add_foreign_key :usda_foods,
|
23
|
+
:usda_food_groups,
|
24
|
+
column: :food_group_code,
|
25
|
+
primary_key: :code
|
26
|
+
|
27
|
+
add_foreign_key :usda_foods_nutrients,
|
28
|
+
:usda_foods,
|
29
|
+
column: :nutrient_databank_number,
|
30
|
+
primary_key: :nutrient_databank_number
|
31
|
+
|
32
|
+
add_foreign_key :usda_foods_nutrients,
|
33
|
+
:usda_nutrients,
|
34
|
+
column: :nutrient_number,
|
35
|
+
primary_key: :nutrient_number
|
36
|
+
|
37
|
+
add_foreign_key :usda_foods_nutrients,
|
38
|
+
:usda_source_codes,
|
39
|
+
column: :src_code,
|
40
|
+
primary_key: :code
|
41
|
+
|
42
|
+
add_foreign_key :usda_footnotes,
|
43
|
+
:usda_foods,
|
44
|
+
column: :nutrient_databank_number,
|
45
|
+
primary_key: :nutrient_databank_number
|
46
|
+
|
47
|
+
add_foreign_key :usda_weights,
|
48
|
+
:usda_foods,
|
49
|
+
column: :nutrient_databank_number,
|
50
|
+
primary_key: :nutrient_databank_number
|
51
|
+
|
52
|
+
add_foreign_key :usda_foods,
|
53
|
+
:usda_food_groups,
|
54
|
+
column: :food_group_code,
|
55
|
+
primary_key: :code
|
56
|
+
|
57
|
+
add_foreign_key :usda_foods_nutrients,
|
58
|
+
:usda_foods,
|
59
|
+
column: :nutrient_databank_number,
|
60
|
+
primary_key: :nutrient_databank_number
|
61
|
+
|
62
|
+
add_foreign_key :usda_foods_nutrients,
|
63
|
+
:usda_nutrients,
|
64
|
+
column: :nutrient_number,
|
65
|
+
primary_key: :nutrient_number
|
66
|
+
|
67
|
+
add_foreign_key :usda_foods_nutrients,
|
68
|
+
:usda_source_codes,
|
69
|
+
column: :src_code,
|
70
|
+
primary_key: :code
|
71
|
+
|
72
|
+
add_foreign_key :usda_footnotes,
|
73
|
+
:usda_foods,
|
74
|
+
column: :nutrient_databank_number,
|
75
|
+
primary_key: :nutrient_databank_number
|
76
|
+
|
77
|
+
add_foreign_key :usda_weights,
|
78
|
+
:usda_foods,
|
79
|
+
column: :nutrient_databank_number,
|
80
|
+
primary_key: :nutrient_databank_number
|
81
|
+
end
|
82
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module UsdaNutrientDatabase
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :logger
|
4
|
-
attr_writer :perform_logging
|
4
|
+
attr_writer :perform_logging,
|
5
|
+
:usda_version
|
5
6
|
|
6
7
|
def logger
|
7
8
|
@logger ||= Logger.new(STDOUT)
|
@@ -10,5 +11,9 @@ module UsdaNutrientDatabase
|
|
10
11
|
def perform_logging?
|
11
12
|
@perform_logging ||= false
|
12
13
|
end
|
14
|
+
|
15
|
+
def usda_version
|
16
|
+
@usda_version || 'sr28'
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
@@ -6,7 +6,7 @@ module UsdaNutrientDatabase
|
|
6
6
|
|
7
7
|
attr_reader :directory, :version
|
8
8
|
|
9
|
-
def initialize(directory = 'tmp/usda', version =
|
9
|
+
def initialize(directory = 'tmp/usda', version = UsdaNutrientDatabase.usda_version)
|
10
10
|
@directory = directory
|
11
11
|
@version = version
|
12
12
|
end
|
@@ -22,9 +22,15 @@ module UsdaNutrientDatabase
|
|
22
22
|
|
23
23
|
def path
|
24
24
|
[
|
25
|
-
'SP2UserFiles',
|
26
|
-
'
|
27
|
-
|
25
|
+
'SP2UserFiles',
|
26
|
+
'Place',
|
27
|
+
'12354500',
|
28
|
+
'Data',
|
29
|
+
version == 'sr28' ? 'SR' : nil,
|
30
|
+
version.upcase,
|
31
|
+
'dnload',
|
32
|
+
"#{version_file}.zip"
|
33
|
+
].compact.join('/')
|
28
34
|
end
|
29
35
|
|
30
36
|
def download
|
@@ -66,6 +72,8 @@ module UsdaNutrientDatabase
|
|
66
72
|
case @version
|
67
73
|
when 'sr27'
|
68
74
|
'sr27asc'
|
75
|
+
when 'sr28'
|
76
|
+
'sr28asc'
|
69
77
|
else
|
70
78
|
@version
|
71
79
|
end
|
@@ -2,7 +2,7 @@ module UsdaNutrientDatabase
|
|
2
2
|
class Importer
|
3
3
|
attr_reader :directory, :version
|
4
4
|
|
5
|
-
def initialize(directory = 'tmp/usda', version =
|
5
|
+
def initialize(directory = 'tmp/usda', version = UsdaNutrientDatabase.usda_version)
|
6
6
|
@directory = directory
|
7
7
|
@version = version
|
8
8
|
end
|
@@ -18,8 +18,13 @@ module UsdaNutrientDatabase
|
|
18
18
|
|
19
19
|
def importer_names
|
20
20
|
[
|
21
|
-
'
|
22
|
-
'
|
21
|
+
'FoodGroups',
|
22
|
+
'SourceCodes',
|
23
|
+
'Nutrients',
|
24
|
+
'Foods',
|
25
|
+
'FoodsNutrients',
|
26
|
+
'Weights',
|
27
|
+
'Footnotes'
|
23
28
|
]
|
24
29
|
end
|
25
30
|
|
@@ -1,7 +1,10 @@
|
|
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(
|
5
|
+
'tmp/usda',
|
6
|
+
UsdaNutrientDatabase.usda_version
|
7
|
+
).import
|
5
8
|
end
|
6
9
|
|
7
10
|
[
|
@@ -15,11 +18,13 @@ namespace :usda do
|
|
15
18
|
end
|
16
19
|
|
17
20
|
def download_and_import(importer_name)
|
18
|
-
UsdaNutrientDatabase::Import::Downloader.new(
|
19
|
-
|
21
|
+
UsdaNutrientDatabase::Import::Downloader.new(
|
22
|
+
'tmp/usda',
|
23
|
+
UsdaNutrientDatabase.usda_version
|
24
|
+
).tap do |downloader|
|
20
25
|
downloader.download_and_unzip
|
21
26
|
"UsdaNutrientDatabase::Import::#{importer_name}".constantize.
|
22
|
-
new('tmp/usda/
|
27
|
+
new('tmp/usda/sr28').import
|
23
28
|
downloader.cleanup
|
24
29
|
end
|
25
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usda-nutrient-database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- db/migrate/6_create_usda_footnotes.rb
|
231
231
|
- db/migrate/7_create_usda_source_codes.rb
|
232
232
|
- db/migrate/8_add_timestamps_to_all_tables.rb
|
233
|
+
- db/migrate/9_add_referential_integrity.rb
|
233
234
|
- lib/usda-nutrient-database.rb
|
234
235
|
- lib/usda_nutrient_database/configuration.rb
|
235
236
|
- lib/usda_nutrient_database/engine.rb
|
@@ -303,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
304
|
version: '0'
|
304
305
|
requirements: []
|
305
306
|
rubyforge_project:
|
306
|
-
rubygems_version: 2.
|
307
|
+
rubygems_version: 2.5.1
|
307
308
|
signing_key:
|
308
309
|
specification_version: 4
|
309
310
|
summary: A gem to include all the USDA nutrient data quickly into a ruby project
|