usda-nutrient-database 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ce03922c74860e2745e15d03f6c272def82a4c5
4
- data.tar.gz: 4fb9cf73acb5c2800f954c6a2c65ff9e431d5e5e
3
+ metadata.gz: 4a67031ae417bd3650d714457de22314526d35c7
4
+ data.tar.gz: 2d335dcbf0e77e332a09e6571caedba77b9f2033
5
5
  SHA512:
6
- metadata.gz: 5e03b8800a02759e631d5222cf2cdf5316c18bc0969f05763915f91624aa7ae53b959635a15f4ec633edaf0307cf03455642649875198bca3d810900a346a141
7
- data.tar.gz: 14a2a5e859edd9af69f602ede9706108a5f723ee5b76f44bcc7f0880633853d486c1a5b4b3cfe991d006c0b5963d21e938b9cf361e9ecfeac31c2271a31acccf
6
+ metadata.gz: f3216c2ea4d030e6713ffca4fc4c3f80b11d57ddf367f3e0c259c512168d8e03659e972416c72827779cbafbecac855680ba35897dd0d46d8762d1b84af98642
7
+ data.tar.gz: 8d3f28d89b7b60a080bb4944b599309aada5cfdb4c10ab23f5bfa18d0f251eda8a54b6d206e9138f8400f05f61c7d13dfcce562f74eca32af7bca0159fec0c8c
@@ -21,5 +21,13 @@ module UsdaNutrientDatabase
21
21
 
22
22
  belongs_to :food_group, class_name: 'UsdaNutrientDatabase::FoodGroup',
23
23
  foreign_key: :food_group_code
24
+
25
+ scope :by_nutrient_number, ->(nutrient_number) {
26
+ joins(:nutrients)
27
+ .where(nutrients: { nutrient_number: nutrient_number })
28
+ }
29
+ scope :by_food_group_code, ->(food_group_code) {
30
+ where(food_group_code: food_group_code)
31
+ }
24
32
  end
25
33
  end
@@ -14,5 +14,12 @@ module UsdaNutrientDatabase
14
14
  foreign_key: :nutrient_databank_number
15
15
  belongs_to :nutrient, class_name: 'UsdaNutrientDatabase::Nutrient',
16
16
  foreign_key: :nutrient_number
17
+
18
+ scope :by_nutrient_databank_number, ->(nutrient_databank_number) {
19
+ where(nutrient_databank_number: nutrient_databank_number)
20
+ }
21
+ scope :by_nutrient_number, ->(nutrient_number) {
22
+ where(nutrient_number: nutrient_number)
23
+ }
17
24
  end
18
25
  end
@@ -12,5 +12,9 @@ module UsdaNutrientDatabase
12
12
  foreign_key: :nutrient_databank_number
13
13
  belongs_to :nutrient, class_name: 'UsdaNutrientDatabase::Nutrient',
14
14
  foreign_key: :nutrient_number
15
+
16
+ scope :by_nutrient_number, ->(nutrient_number) {
17
+ where(nutrient_number: nutrient_number)
18
+ }
15
19
  end
16
20
  end
@@ -6,7 +6,7 @@ module UsdaNutrientDatabase
6
6
 
7
7
  attr_reader :directory, :version
8
8
 
9
- def initialize(directory = 'tmp/usda', version = 'sr25')
9
+ def initialize(directory = 'tmp/usda', version = 'sr27')
10
10
  @directory = directory
11
11
  @version = version
12
12
  end
@@ -55,7 +55,7 @@ module UsdaNutrientDatabase
55
55
  def final_path
56
56
  look_ahead = connection.head(path)
57
57
  if look_ahead.status == 302
58
- raise 'No location' unless look_ahead.headers['location']
58
+ raise 'No location' unless look_ahead.headers['location']
59
59
  URI.parse(look_ahead.headers['location']).path
60
60
  else
61
61
  path
@@ -13,11 +13,17 @@ module UsdaNutrientDatabase
13
13
 
14
14
  has_many :foods_nutrients,
15
15
  class_name: 'UsdaNutrientDatabase::FoodsNutrient',
16
- dependent: :destroy, foreign_key: :nutrient_number,
16
+ foreign_key: :nutrient_number,
17
17
  dependent: :nullify
18
18
  has_many :foods, class_name: 'UsdaNutrientDatabase::Food',
19
19
  through: :foods_nutrients
20
20
  has_many :footnotes, class_name: 'UsdaNutrientDatabase::Footnote',
21
21
  foreign_key: :nutrient_number
22
+
23
+ scope :by_nutrient_databank_number, ->(nutrient_databank_number) {
24
+ joins(:foods).where(
25
+ usda_foods: { nutrient_databank_number: nutrient_databank_number }
26
+ )
27
+ }
22
28
  end
23
29
  end
@@ -1,7 +1,7 @@
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', 'sr26').import
4
+ UsdaNutrientDatabase::Importer.new('tmp/usda', 'sr27').import
5
5
  end
6
6
 
7
7
  [
@@ -15,11 +15,11 @@ namespace :usda do
15
15
  end
16
16
 
17
17
  def download_and_import(importer_name)
18
- UsdaNutrientDatabase::Import::Downloader.new('tmp/usda', 'sr26').
18
+ UsdaNutrientDatabase::Import::Downloader.new('tmp/usda', 'sr27').
19
19
  tap do |downloader|
20
20
  downloader.download_and_unzip
21
21
  "UsdaNutrientDatabase::Import::#{importer_name}".constantize.
22
- new('tmp/usda/sr25').import
22
+ new('tmp/usda/sr27').import
23
23
  downloader.cleanup
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module UsdaNutrientDatabase
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -12,5 +12,9 @@ module UsdaNutrientDatabase
12
12
 
13
13
  belongs_to :food, class_name: 'UsdaNutrientDatabase::Food',
14
14
  foreign_key: :nutrient_databank_number
15
+
16
+ scope :by_nutrient_databank_number, ->(nutrient_databank_number) {
17
+ where(nutrient_databank_number: nutrient_databank_number)
18
+ }
15
19
  end
16
20
  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.2.0
4
+ version: 1.3.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-06-21 00:00:00.000000000 Z
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord