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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a67031ae417bd3650d714457de22314526d35c7
4
- data.tar.gz: 2d335dcbf0e77e332a09e6571caedba77b9f2033
3
+ metadata.gz: a1e7f2d97c62a659ed44c93cbaf15975196107cd
4
+ data.tar.gz: 4ce234c30e8b5fc058fdd8960d2fd3dcfe416707
5
5
  SHA512:
6
- metadata.gz: f3216c2ea4d030e6713ffca4fc4c3f80b11d57ddf367f3e0c259c512168d8e03659e972416c72827779cbafbecac855680ba35897dd0d46d8762d1b84af98642
7
- data.tar.gz: 8d3f28d89b7b60a080bb4944b599309aada5cfdb4c10ab23f5bfa18d0f251eda8a54b6d206e9138f8400f05f61c7d13dfcce562f74eca32af7bca0159fec0c8c
6
+ metadata.gz: 7d3104e79ce945684f7550a77f8edada72dc5159460aaaeccc972fdb2c306d4438f275cac30a9906ac75b0b5aa32562bbc68794cec1bcb670c1bad0dd34974e4
7
+ data.tar.gz: 55c2bc53e7260685b3a6352ad904ca516760afa188c67fc5bdd7d9bb1b0bfee2a7fc71b9bb4b21e89ac444043686f42cec46681dc2a0c2846c1410fa3ef1379c
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.3.0
4
+ - 2.2.0
5
+ - 2.1.0
3
6
  - 2.0.0
4
7
  - 1.9.3
5
8
  before_install:
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
- UsedNutrientDatabase::Nutrient
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
@@ -35,6 +35,10 @@ module UsdaNutrientDatabase
35
35
  def configuration
36
36
  @configuration ||= UsdaNutrientDatabase::Configuration.new
37
37
  end
38
+
39
+ def usda_version
40
+ @usda_version ||= configuration.usda_version
41
+ end
38
42
  end
39
43
 
40
44
  def self.configure
@@ -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
@@ -19,7 +19,7 @@ module UsdaNutrientDatabase
19
19
  attr_reader :directory
20
20
 
21
21
  def extract_row(row)
22
- build_object(apply_typecasts(row)).save
22
+ build_object(apply_typecasts(row)).save!
23
23
  end
24
24
 
25
25
  def build_object(row)
@@ -6,7 +6,7 @@ module UsdaNutrientDatabase
6
6
 
7
7
  attr_reader :directory, :version
8
8
 
9
- def initialize(directory = 'tmp/usda', version = 'sr27')
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', 'Place', '12354500', 'Data', version.upcase,
26
- 'dnload', "#{version_file}.zip"
27
- ].join('/')
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 = 'sr25')
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
- 'Foods', 'Nutrients', 'FoodsNutrients', 'FoodGroups', 'Weights',
22
- 'Footnotes', 'SourceCodes'
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('tmp/usda', 'sr27').import
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('tmp/usda', 'sr27').
19
- tap do |downloader|
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/sr27').import
27
+ new('tmp/usda/sr28').import
23
28
  downloader.cleanup
24
29
  end
25
30
  end
@@ -1,3 +1,3 @@
1
1
  module UsdaNutrientDatabase
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  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.3.0
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: 2015-08-03 00:00:00.000000000 Z
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.4.5
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