usda-nutrient-database 0.7.0 → 0.8.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/db/migrate/7_create_usda_source_codes.rb +8 -0
- data/lib/usda-nutrient-database.rb +2 -0
- data/lib/usda_nutrient_database/import/source_codes.rb +32 -0
- data/lib/usda_nutrient_database/importer.rb +1 -1
- data/lib/usda_nutrient_database/source_code.rb +8 -0
- data/lib/usda_nutrient_database/tasks/usda_nutrient_database.rake +1 -1
- data/lib/usda_nutrient_database/version.rb +1 -1
- data/spec/lib/usda_nutrient_database/import/source_codes_spec.rb +11 -0
- data/spec/lib/usda_nutrient_database/source_code_spec.rb +6 -0
- data/spec/schema.rb +5 -0
- data/spec/support/sr25/SRC_CD.txt +10 -0
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b42f531ff7c230d3919588d494959eece641d3da
|
4
|
+
data.tar.gz: ed76e91f607b9fab45a23f0924bf621b92a214d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d340641c0bf0a2f7ac3b015c5e6f5ef4104e283123fcfeb7c40f9d2423f36a18af3fea84f2a94585cb3a614d6599e678c05ad043b1f929cef21cf45816fa84
|
7
|
+
data.tar.gz: 0169c9352a7086619ccb831330683a35fd5f399dca89e17ce5e4dbc4714dc871bfd38f8afe4c5e0359f9b97b9a8e4c4234eaebaa5d697b39c68dbe402b516724
|
@@ -6,6 +6,7 @@ require 'usda_nutrient_database/food'
|
|
6
6
|
require 'usda_nutrient_database/footnote'
|
7
7
|
require 'usda_nutrient_database/nutrient'
|
8
8
|
require 'usda_nutrient_database/foods_nutrient'
|
9
|
+
require 'usda_nutrient_database/source_code'
|
9
10
|
require 'usda_nutrient_database/importer'
|
10
11
|
require 'usda_nutrient_database/import/base'
|
11
12
|
require 'usda_nutrient_database/import/downloader'
|
@@ -14,6 +15,7 @@ require 'usda_nutrient_database/import/foods'
|
|
14
15
|
require 'usda_nutrient_database/import/foods_nutrients'
|
15
16
|
require 'usda_nutrient_database/import/footnotes'
|
16
17
|
require 'usda_nutrient_database/import/nutrients'
|
18
|
+
require 'usda_nutrient_database/import/source_codes'
|
17
19
|
require 'usda_nutrient_database/import/weights'
|
18
20
|
require 'usda_nutrient_database/railtie' if defined?(Rails)
|
19
21
|
require 'usda_nutrient_database/version'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module UsdaNutrientDatabase
|
2
|
+
module Import
|
3
|
+
class SourceCodes < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def extract_row(row)
|
8
|
+
build_source_code(row).save
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_source_code(row)
|
12
|
+
UsdaNutrientDatabase::SourceCode.new.tap do |source_code|
|
13
|
+
columns.each_with_index do |column, index|
|
14
|
+
source_code.send("#{column}=", row[index])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def columns
|
20
|
+
[:code, :description]
|
21
|
+
end
|
22
|
+
|
23
|
+
def log_import_started
|
24
|
+
UsdaNutrientDatabase.log 'Source code import started'
|
25
|
+
end
|
26
|
+
|
27
|
+
def filename
|
28
|
+
'SRC_CD.txt'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UsdaNutrientDatabase::Import::SourceCodes do
|
4
|
+
let(:importer) { described_class.new('spec/support/sr25') }
|
5
|
+
|
6
|
+
describe '#import' do
|
7
|
+
before { importer.import }
|
8
|
+
|
9
|
+
it { expect(UsdaNutrientDatabase::SourceCode.count).to eql(10) }
|
10
|
+
end
|
11
|
+
end
|
data/spec/schema.rb
CHANGED
@@ -67,4 +67,9 @@ ActiveRecord::Schema.define version: 0 do
|
|
67
67
|
t.string :nutrient_number, index: true
|
68
68
|
t.string :footnote_text, null: false
|
69
69
|
end
|
70
|
+
|
71
|
+
create_table :usda_source_codes, force: true do |t|
|
72
|
+
t.string :code, null: false, index: true
|
73
|
+
t.string :description, null: false
|
74
|
+
end
|
70
75
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
~1~^~Analytical or derived from analytical~
|
2
|
+
~4~^~Calculated or imputed~
|
3
|
+
~5~^~Value manufacturer based label claim for added nutrients~
|
4
|
+
~6~^~Aggregated data involving combinations of source codes 1 &12~
|
5
|
+
~7~^~Assumed zero~
|
6
|
+
~8~^~Calculated from nutrient label by NDL~
|
7
|
+
~9~^~Calculated by manufacturer, not adjusted or rounded for NLEA~
|
8
|
+
~11~^~Aggregated data involving comb. of codes other then 1,12 or6~
|
9
|
+
~12~^~Manufacturer's analytical; partial documentation~
|
10
|
+
~13~^~Analytical data from the literature, partial documentation~
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Beedle
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- db/migrate/4_create_usda_nutrients.rb
|
199
199
|
- db/migrate/5_create_usda_weights.rb
|
200
200
|
- db/migrate/6_create_usda_footnotes.rb
|
201
|
+
- db/migrate/7_create_usda_source_codes.rb
|
201
202
|
- lib/usda-nutrient-database.rb
|
202
203
|
- lib/usda_nutrient_database/configuration.rb
|
203
204
|
- lib/usda_nutrient_database/engine.rb
|
@@ -212,10 +213,12 @@ files:
|
|
212
213
|
- lib/usda_nutrient_database/import/foods_nutrients.rb
|
213
214
|
- lib/usda_nutrient_database/import/footnotes.rb
|
214
215
|
- lib/usda_nutrient_database/import/nutrients.rb
|
216
|
+
- lib/usda_nutrient_database/import/source_codes.rb
|
215
217
|
- lib/usda_nutrient_database/import/weights.rb
|
216
218
|
- lib/usda_nutrient_database/importer.rb
|
217
219
|
- lib/usda_nutrient_database/nutrient.rb
|
218
220
|
- lib/usda_nutrient_database/railtie.rb
|
221
|
+
- lib/usda_nutrient_database/source_code.rb
|
219
222
|
- lib/usda_nutrient_database/tasks/usda_nutrient_database.rake
|
220
223
|
- lib/usda_nutrient_database/version.rb
|
221
224
|
- lib/usda_nutrient_database/weight.rb
|
@@ -230,9 +233,11 @@ files:
|
|
230
233
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
231
234
|
- spec/lib/usda_nutrient_database/import/footnotes_spec.rb
|
232
235
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
236
|
+
- spec/lib/usda_nutrient_database/import/source_codes_spec.rb
|
233
237
|
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
234
238
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
235
239
|
- spec/lib/usda_nutrient_database/nutrient_spec.rb
|
240
|
+
- spec/lib/usda_nutrient_database/source_code_spec.rb
|
236
241
|
- spec/lib/usda_nutrient_database/weight_spec.rb
|
237
242
|
- spec/schema.rb
|
238
243
|
- spec/spec_helper.rb
|
@@ -242,6 +247,7 @@ files:
|
|
242
247
|
- spec/support/sr25/FOOTNOTE.txt
|
243
248
|
- spec/support/sr25/NUTR_DEF.txt
|
244
249
|
- spec/support/sr25/NUT_DATA.txt
|
250
|
+
- spec/support/sr25/SRC_CD.txt
|
245
251
|
- spec/support/sr25/WEIGHT.txt
|
246
252
|
- usda-nutrient-database.gemspec
|
247
253
|
homepage: https://github.com/mattbeedle/usda-nutrient-database
|
@@ -280,9 +286,11 @@ test_files:
|
|
280
286
|
- spec/lib/usda_nutrient_database/import/foods_spec.rb
|
281
287
|
- spec/lib/usda_nutrient_database/import/footnotes_spec.rb
|
282
288
|
- spec/lib/usda_nutrient_database/import/nutrients_spec.rb
|
289
|
+
- spec/lib/usda_nutrient_database/import/source_codes_spec.rb
|
283
290
|
- spec/lib/usda_nutrient_database/import/weights_spec.rb
|
284
291
|
- spec/lib/usda_nutrient_database/importer_spec.rb
|
285
292
|
- spec/lib/usda_nutrient_database/nutrient_spec.rb
|
293
|
+
- spec/lib/usda_nutrient_database/source_code_spec.rb
|
286
294
|
- spec/lib/usda_nutrient_database/weight_spec.rb
|
287
295
|
- spec/schema.rb
|
288
296
|
- spec/spec_helper.rb
|
@@ -292,4 +300,5 @@ test_files:
|
|
292
300
|
- spec/support/sr25/FOOTNOTE.txt
|
293
301
|
- spec/support/sr25/NUTR_DEF.txt
|
294
302
|
- spec/support/sr25/NUT_DATA.txt
|
303
|
+
- spec/support/sr25/SRC_CD.txt
|
295
304
|
- spec/support/sr25/WEIGHT.txt
|