foodnutritionix 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +1 -21
- data/README.md +2 -0
- data/foodnutritionix.gemspec +5 -4
- data/lib/foodnutritionix/food.rb +28 -20
- data/lib/foodnutritionix/foodnutrix_api.rb +0 -1
- data/lib/foodnutritionix/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +33 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8836e934f7cb0ea2c4f35e2e6f24a077e7ae2d64
|
4
|
+
data.tar.gz: 0d97c423bff77f1b2f96c0d05756c07c7b860bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9186ac8600cf4b5ed7a99c6acd0c5a66c154468bfee54d9f6b25f13830410df3fbd8a86ab5bb324a24076badc843a2025b164687b1333a5d2cd0b567480615e
|
7
|
+
data.tar.gz: b55a8e506a5d30631504f0437bc16154bdd6e68381bb914857a693a4fe156b627630cc4b1d2a4a9fa89b8cfcc1b2fde714995efe837d75b2d5b93b6dbf893a69
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,24 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
ruby '2.3.1'
|
3
|
-
|
4
2
|
source 'https://rubygems.org'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
gem 'flog'
|
9
|
-
gem 'flay'
|
10
|
-
|
11
|
-
gem 'httparty'
|
12
|
-
|
13
|
-
gem 'minitest'
|
14
|
-
gem 'minitest-rg'
|
15
|
-
|
16
|
-
gem 'pry-coolline'
|
17
|
-
|
18
|
-
gem 'rake'
|
19
|
-
gem 'rubocop'
|
20
|
-
|
21
|
-
gem 'vcr'
|
22
|
-
gem 'webmock'
|
23
|
-
|
24
|
-
gem 'simplecov'
|
4
|
+
gemspec
|
data/README.md
CHANGED
data/foodnutritionix.gemspec
CHANGED
@@ -16,17 +16,18 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_runtime_dependency 'httparty', '~> 0.14'
|
18
18
|
|
19
|
+
|
19
20
|
s.add_development_dependency 'dotenv', '~> 2.1'
|
21
|
+
s.add_development_dependency 'flog', '~> 4.4'
|
22
|
+
s.add_development_dependency 'flay', '~> 2.8'
|
23
|
+
s.add_development_dependency 'httparty', '~> 0.14'
|
20
24
|
s.add_development_dependency 'minitest', '~> 5.9'
|
21
25
|
s.add_development_dependency 'minitest-rg', '~> 5.2'
|
22
26
|
s.add_development_dependency 'rake', '~> 11.3'
|
27
|
+
s.add_development_dependency 'rubocop', '~> 0.42'
|
23
28
|
s.add_development_dependency 'vcr', '~> 3.0'
|
24
29
|
s.add_development_dependency 'webmock', '~> 2.1'
|
25
30
|
s.add_development_dependency 'simplecov', '~> 0.12'
|
26
|
-
s.add_development_dependency 'flog', '~> 4.4'
|
27
|
-
s.add_development_dependency 'flay', '~> 2.8'
|
28
|
-
s.add_development_dependency 'rubocop', '~> 0.42'
|
29
|
-
s.add_development_dependency 'httparty', '~> 0.14'
|
30
31
|
|
31
32
|
s.homepage = 'https://github.com/NoBetterThan97/FoodNutritionix'
|
32
33
|
s.license = 'MIT'
|
data/lib/foodnutritionix/food.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module FoodNutritionix
|
3
3
|
class Food
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
ATTRIBUTES = [:name,
|
5
|
+
:serving_quantity,
|
6
|
+
:serving_unit,
|
7
|
+
:serving_weight,
|
8
|
+
:calories,
|
9
|
+
:fat,
|
10
|
+
:saturated_fat,
|
11
|
+
:cholesterol,
|
12
|
+
:sodium,
|
13
|
+
:carbohydrate,
|
14
|
+
:dietary_fiber,
|
15
|
+
:sugars,
|
16
|
+
:protein,
|
17
|
+
:potassium,
|
18
|
+
:photo].freeze
|
19
|
+
attr_reader(*ATTRIBUTES)
|
19
20
|
|
20
21
|
def initialize(data)
|
21
22
|
@name = data['food_name']
|
@@ -24,6 +25,18 @@ module FoodNutritionix
|
|
24
25
|
@photo = data['photo']
|
25
26
|
end
|
26
27
|
|
28
|
+
def to_hash
|
29
|
+
ATTRIBUTES.map { |attribute| [attribute, send(attribute)] }.to_h
|
30
|
+
end
|
31
|
+
alias to_h to_hash
|
32
|
+
|
33
|
+
def self.search(*names)
|
34
|
+
FoodNutrixClient.search_foods(names)
|
35
|
+
&.map { |food| new(food) }
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
27
40
|
def populate_serving_information(data)
|
28
41
|
@serving_quantity = data['serving_qty']
|
29
42
|
@serving_unit = data['serving_unit']
|
@@ -42,10 +55,5 @@ module FoodNutritionix
|
|
42
55
|
@protein = data.fetch('nf_protein', 0.0)
|
43
56
|
@potassium = data.fetch('nf_potassium', 0.0)
|
44
57
|
end
|
45
|
-
|
46
|
-
def self.search(*names)
|
47
|
-
FoodNutrixClient.search_foods(names)
|
48
|
-
&.map { |food| new(food) }
|
49
|
-
end
|
50
58
|
end
|
51
59
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foodnutritionix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leo Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -39,145 +39,145 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: flog
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: flay
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.8'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: httparty
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0.14'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0.14'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: minitest
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '5.9'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '5.9'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: minitest-rg
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2
|
103
|
+
version: '5.2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2
|
110
|
+
version: '5.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '11.3'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '11.3'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0.42'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0.42'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: vcr
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '3.0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '3.0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: webmock
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '2.1'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '2.1'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '0.
|
173
|
+
version: '0.12'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '0.
|
180
|
+
version: '0.12'
|
181
181
|
description: Get name, search time, unit, qty, weight, nutrients, calories, photo
|
182
182
|
email:
|
183
183
|
- leo.li@iss.nthu.edu.tw
|
@@ -187,6 +187,7 @@ extra_rdoc_files: []
|
|
187
187
|
files:
|
188
188
|
- ".gitignore"
|
189
189
|
- ".rubocop.yml"
|
190
|
+
- ".travis.yml"
|
190
191
|
- Gemfile
|
191
192
|
- Gemfile.lock
|
192
193
|
- LICENSE.md
|