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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bd17f02eed2f395e8f952043fbdefa139bccec3
4
- data.tar.gz: 2a65d9b31e2a8c27232e0a4942b1eb2476c4df04
3
+ metadata.gz: b42f531ff7c230d3919588d494959eece641d3da
4
+ data.tar.gz: ed76e91f607b9fab45a23f0924bf621b92a214d5
5
5
  SHA512:
6
- metadata.gz: df47134fa7024b7690ea229df7b1e5d67e49c99251c2d8596bbb5dfc34adf93a9af28b440d658662719cbccfee64dd8c4339d10a2c59ddacc646e021fd2e2004
7
- data.tar.gz: 7d525913e661f9956a5e343738b140b4e6e32c51aeea55c63f1376dce9c747768dcb88523e9ded0090e85554a8cce2fe1e3d668162e9ca009045354b481a90a4
6
+ metadata.gz: 90d340641c0bf0a2f7ac3b015c5e6f5ef4104e283123fcfeb7c40f9d2423f36a18af3fea84f2a94585cb3a614d6599e678c05ad043b1f929cef21cf45816fa84
7
+ data.tar.gz: 0169c9352a7086619ccb831330683a35fd5f399dca89e17ce5e4dbc4714dc871bfd38f8afe4c5e0359f9b97b9a8e4c4234eaebaa5d697b39c68dbe402b516724
@@ -0,0 +1,8 @@
1
+ class CreateUsdaSourceCodes < ActiveRecord::Migration
2
+ def change
3
+ create_table :usda_source_codes do |t|
4
+ t.string :code, null: false, index: true
5
+ t.string :description, null: false
6
+ end
7
+ end
8
+ end
@@ -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
@@ -19,7 +19,7 @@ module UsdaNutrientDatabase
19
19
  def importer_names
20
20
  [
21
21
  'Foods', 'Nutrients', 'FoodsNutrients', 'FoodGroups', 'Weights',
22
- 'Footnotes'
22
+ 'Footnotes', 'SourceCodes'
23
23
  ]
24
24
  end
25
25
 
@@ -0,0 +1,8 @@
1
+ module UsdaNutrientDatabase
2
+ class SourceCode < ActiveRecord::Base
3
+ self.table_name = 'usda_source_codes'
4
+
5
+ validates :code, presence: true, uniqueness: { allow_blank: true }
6
+ validates :description, presence: true
7
+ end
8
+ end
@@ -6,7 +6,7 @@ namespace :usda do
6
6
 
7
7
  [
8
8
  'Weights', 'Footnotes', 'FoodGroups', 'Foods', 'FoodsNutrients',
9
- 'Nutrients'
9
+ 'Nutrients', 'SourceCodes'
10
10
  ].each do |importer_name|
11
11
  desc "Import the USDA #{importer_name} table"
12
12
  task import_weights: :environment do
@@ -1,3 +1,3 @@
1
1
  module UsdaNutrientDatabase
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  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
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe UsdaNutrientDatabase::SourceCode do
4
+ it { validate_presence_of(:code) }
5
+ it { validate_presence_of(:description) }
6
+ 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.7.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