usda-nutrient-database 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/6_create_footnotes.rb +11 -0
- data/lib/usda-nutrient-database.rb +2 -0
- data/lib/usda_nutrient_database/food.rb +2 -0
- data/lib/usda_nutrient_database/footnote.rb +15 -0
- data/lib/usda_nutrient_database/import/footnotes.rb +34 -0
- data/lib/usda_nutrient_database/nutrient.rb +2 -0
- data/lib/usda_nutrient_database/version.rb +1 -1
- data/spec/lib/usda_nutrient_database/footnote_spec.rb +8 -0
- data/spec/lib/usda_nutrient_database/import/footnotes_spec.rb +11 -0
- data/spec/schema.rb +8 -0
- data/spec/support/sr25/FOOTNOTE.txt +4 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a1a20a7ca11fed27457609ba81d0247479c4b90
|
4
|
+
data.tar.gz: 1e7911deeb66f62d4e5c36cc669d73b8b1f1b340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea25431873fbaaedab58f4f24ae48c8c8f8962cb86d8b4853e6ced769c7f4e64517416a8680fc636f977dad04038dcdf256ca2db487c68691fd998f0a9bdd74
|
7
|
+
data.tar.gz: 6e4715beb8efd19a3cbe94a5f3387cda8f78924d06fe8980eb260a00e2ad1b999197a315f2451d879b6d87e1210590ac14cd408cf08d06f30949ba91dbde49af
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateFootnotes < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :usda_footnotes do |t|
|
4
|
+
t.string :nutrient_databank_number, null: false, index: true
|
5
|
+
t.string :footnote_number, null: false, index: true
|
6
|
+
t.string :footnote_type, null: false, index: true
|
7
|
+
t.string :nutrient_number, index: true
|
8
|
+
t.string :footnote_text, null: false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -3,6 +3,7 @@ require 'usda_nutrient_database/configuration'
|
|
3
3
|
require 'usda_nutrient_database/engine' if defined?(Rails)
|
4
4
|
require 'usda_nutrient_database/food_group'
|
5
5
|
require 'usda_nutrient_database/food'
|
6
|
+
require 'usda_nutrient_database/footnote'
|
6
7
|
require 'usda_nutrient_database/nutrient'
|
7
8
|
require 'usda_nutrient_database/foods_nutrient'
|
8
9
|
require 'usda_nutrient_database/importer'
|
@@ -11,6 +12,7 @@ require 'usda_nutrient_database/import/downloader'
|
|
11
12
|
require 'usda_nutrient_database/import/food_groups'
|
12
13
|
require 'usda_nutrient_database/import/foods'
|
13
14
|
require 'usda_nutrient_database/import/foods_nutrients'
|
15
|
+
require 'usda_nutrient_database/import/footnotes'
|
14
16
|
require 'usda_nutrient_database/import/nutrients'
|
15
17
|
require 'usda_nutrient_database/import/weights'
|
16
18
|
require 'usda_nutrient_database/railtie' if defined?(Rails)
|
@@ -9,6 +9,8 @@ module UsdaNutrientDatabase
|
|
9
9
|
validates :long_description, presence: true
|
10
10
|
validates :short_description, presence: true
|
11
11
|
|
12
|
+
has_many :footnotes, class_name: 'UsdaNutrientDatabase::Footnote'
|
13
|
+
|
12
14
|
belongs_to :food_group, class_name: 'UsdaNutrientDatabase::FoodGroup',
|
13
15
|
foreign_key: :food_group_code
|
14
16
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module UsdaNutrientDatabase
|
2
|
+
class Footnote < ActiveRecord::Base
|
3
|
+
self.table_name = 'usda_footnotes'
|
4
|
+
|
5
|
+
validates :nutrient_databank_number, presence: true
|
6
|
+
validates :footnote_number, presence: true
|
7
|
+
validates :footnote_type, presence: true
|
8
|
+
validates :footnote_text, presence: true
|
9
|
+
|
10
|
+
belongs_to :food, class_name: 'UsdaNutrientDatabase::Food',
|
11
|
+
foreign_key: :nutrient_databank_number
|
12
|
+
belongs_to :nutrient, class_name: 'UsdaNutrientDatabase::Nutrient',
|
13
|
+
foreign_key: :nutrient_number
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module UsdaNutrientDatabase
|
2
|
+
module Import
|
3
|
+
class Footnotes < Base
|
4
|
+
def import
|
5
|
+
CSV.open(
|
6
|
+
"#{directory}/FOOTNOTE.txt", 'r:iso-8859-1:utf-8', csv_options
|
7
|
+
) do |csv|
|
8
|
+
csv.each { |row| extract_row(row) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def extract_row(row)
|
15
|
+
UsdaNutrientDatabase::Footnote.create! extract_row_data(row)
|
16
|
+
end
|
17
|
+
|
18
|
+
def extract_row_data(row)
|
19
|
+
{}.tap do |attrs|
|
20
|
+
columns.each_with_index do |col, index|
|
21
|
+
attrs.merge!(col => row[index])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def columns
|
27
|
+
[
|
28
|
+
:nutrient_databank_number, :footnote_number, :footnote_type,
|
29
|
+
:nutrient_number, :footnote_text
|
30
|
+
]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsdaNutrientDatabase::Footnote do
|
4
|
+
it { should validate_presence_of(:nutrient_databank_number) }
|
5
|
+
it { should validate_presence_of(:footnote_number) }
|
6
|
+
it { should validate_presence_of(:footnote_type) }
|
7
|
+
it { should validate_presence_of(:footnote_text) }
|
8
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsdaNutrientDatabase::Import::Footnotes do
|
4
|
+
let(:importer) { described_class.new('spec/support/sr25') }
|
5
|
+
|
6
|
+
describe '#import' do
|
7
|
+
before { importer.import }
|
8
|
+
|
9
|
+
it { expect(UsdaNutrientDatabase::Footnote.count).to eql(4) }
|
10
|
+
end
|
11
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -59,4 +59,12 @@ ActiveRecord::Schema.define version: 0 do
|
|
59
59
|
t.integer :num_data_points
|
60
60
|
t.float :standard_deviation
|
61
61
|
end
|
62
|
+
|
63
|
+
create_table :usda_footnotes, force: true do |t|
|
64
|
+
t.string :nutrient_databank_number, null: false, index: true
|
65
|
+
t.string :footnote_number, null: false, index: true
|
66
|
+
t.string :footnote_type, null: false, index: true
|
67
|
+
t.string :nutrient_number, index: true
|
68
|
+
t.string :footnote_text, null: false
|
69
|
+
end
|
62
70
|
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
~02009~^~01~^~D~^~~^~Mix of chili pepper, other spices and salt~
|
2
|
+
~02030~^~01~^~N~^~204~^~Total proximates do not equal 100% because piperine was subtracted from lipid value.~
|
3
|
+
~02032~^~01~^~N~^~204~^~Total proximates do not equal 100% because piperine was subtracted from lipid value.~
|
4
|
+
~02033~^~01~^~D~^~~^~Other phytosterols = 38.4 mg/100g; these include delta 5-avenasterol (17.7), campestanol (2.6), and other minor phytosterols (18.1 mg).~
|
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: 0.
|
4
|
+
version: 0.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: 2013-12-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- db/migrate/3_create_usda_foods_nutrients.rb
|
198
198
|
- db/migrate/4_create_usda_nutrients.rb
|
199
199
|
- db/migrate/5_create_usda_weights.rb
|
200
|
+
- db/migrate/6_create_footnotes.rb
|
200
201
|
- lib/tasks/usda_nutrient_database.rake
|
201
202
|
- lib/usda-nutrient-database.rb
|
202
203
|
- lib/usda_nutrient_database/configuration.rb
|
@@ -204,11 +205,13 @@ files:
|
|
204
205
|
- lib/usda_nutrient_database/food.rb
|
205
206
|
- lib/usda_nutrient_database/food_group.rb
|
206
207
|
- lib/usda_nutrient_database/foods_nutrient.rb
|
208
|
+
- lib/usda_nutrient_database/footnote.rb
|
207
209
|
- lib/usda_nutrient_database/import/base.rb
|
208
210
|
- lib/usda_nutrient_database/import/downloader.rb
|
209
211
|
- lib/usda_nutrient_database/import/food_groups.rb
|
210
212
|
- lib/usda_nutrient_database/import/foods.rb
|
211
213
|
- lib/usda_nutrient_database/import/foods_nutrients.rb
|
214
|
+
- lib/usda_nutrient_database/import/footnotes.rb
|
212
215
|
- lib/usda_nutrient_database/import/nutrients.rb
|
213
216
|
- lib/usda_nutrient_database/import/weights.rb
|
214
217
|
- lib/usda_nutrient_database/importer.rb
|
@@ -220,10 +223,12 @@ files:
|
|
220
223
|
- spec/lib/usda_nutrient_database/food_group_spec.rb
|
221
224
|
- spec/lib/usda_nutrient_database/food_spec.rb
|
222
225
|
- spec/lib/usda_nutrient_database/foods_nutrient_spec.rb
|
226
|
+
- spec/lib/usda_nutrient_database/footnote_spec.rb
|
223
227
|
- spec/lib/usda_nutrient_database/import/downloader_spec.rb
|
224
228
|
- spec/lib/usda_nutrient_database/import/food_groups_spec.rb
|
225
229
|
- spec/lib/usda_nutrient_database/import/foods_nutrients_spec.rb
|
226
230
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
231
|
+
- spec/lib/usda_nutrient_database/import/footnotes_spec.rb
|
227
232
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
228
233
|
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
229
234
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
@@ -234,6 +239,7 @@ files:
|
|
234
239
|
- spec/support/sr25.zip
|
235
240
|
- spec/support/sr25/FD_GROUP.txt
|
236
241
|
- spec/support/sr25/FOOD_DES.txt
|
242
|
+
- spec/support/sr25/FOOTNOTE.txt
|
237
243
|
- spec/support/sr25/NUTR_DEF.txt
|
238
244
|
- spec/support/sr25/NUT_DATA.txt
|
239
245
|
- spec/support/sr25/WEIGHT.txt
|
@@ -258,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
264
|
version: '0'
|
259
265
|
requirements: []
|
260
266
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.
|
267
|
+
rubygems_version: 2.0.3
|
262
268
|
signing_key:
|
263
269
|
specification_version: 4
|
264
270
|
summary: A gem to include all the USDA nutrient data quickly into a ruby project
|
@@ -267,10 +273,12 @@ test_files:
|
|
267
273
|
- spec/lib/usda_nutrient_database/food_group_spec.rb
|
268
274
|
- spec/lib/usda_nutrient_database/food_spec.rb
|
269
275
|
- spec/lib/usda_nutrient_database/foods_nutrient_spec.rb
|
276
|
+
- spec/lib/usda_nutrient_database/footnote_spec.rb
|
270
277
|
- spec/lib/usda_nutrient_database/import/downloader_spec.rb
|
271
278
|
- spec/lib/usda_nutrient_database/import/food_groups_spec.rb
|
272
279
|
- spec/lib/usda_nutrient_database/import/foods_nutrients_spec.rb
|
273
280
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
281
|
+
- spec/lib/usda_nutrient_database/import/footnotes_spec.rb
|
274
282
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
275
283
|
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
276
284
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
@@ -281,6 +289,7 @@ test_files:
|
|
281
289
|
- spec/support/sr25.zip
|
282
290
|
- spec/support/sr25/FD_GROUP.txt
|
283
291
|
- spec/support/sr25/FOOD_DES.txt
|
292
|
+
- spec/support/sr25/FOOTNOTE.txt
|
284
293
|
- spec/support/sr25/NUTR_DEF.txt
|
285
294
|
- spec/support/sr25/NUT_DATA.txt
|
286
295
|
- spec/support/sr25/WEIGHT.txt
|