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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32924569f95bfa9ace691b227eceb2333fa26a37
4
- data.tar.gz: 105c8e3d6d76752939e32db1e128591438ad9c42
3
+ metadata.gz: 8836e934f7cb0ea2c4f35e2e6f24a077e7ae2d64
4
+ data.tar.gz: 0d97c423bff77f1b2f96c0d05756c07c7b860bb1
5
5
  SHA512:
6
- metadata.gz: dadfc90fe834b9ed3cff14e2f4d238a2b4e678bb8e997d0920c777abb2845ac9be2a289a6d4e3ef0d4b098de2400fa6f1e01d90ae3890cbaafed025ec6f21e4e
7
- data.tar.gz: 5a5fd8da378208266205556b463966e69694941790e48ebf4a3165422ed317a441954a6d425559904dca2cc3bfd5570617a456904b2273bde26b65db6c870075
6
+ metadata.gz: a9186ac8600cf4b5ed7a99c6acd0c5a66c154468bfee54d9f6b25f13830410df3fbd8a86ab5bb324a24076badc843a2025b164687b1333a5d2cd0b567480615e
7
+ data.tar.gz: b55a8e506a5d30631504f0437bc16154bdd6e68381bb914857a693a4fe156b627630cc4b1d2a4a9fa89b8cfcc1b2fde714995efe837d75b2d5b93b6dbf893a69
data/.gitignore CHANGED
@@ -12,3 +12,6 @@ Gemfile.lock
12
12
 
13
13
  # product
14
14
  *.gem
15
+
16
+ # rbenv
17
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.3.1
5
+ - 2.3.2
6
+ - 2.3.3
7
+ script:
8
+ - bundle exec rake test
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
- gem 'dotenv'
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
@@ -1,3 +1,5 @@
1
1
  # FoodNutritionix Gem
2
2
 
3
+ [![Build Status](https://travis-ci.org/NoBetterThan97/FoodNutritionix.svg?branch=master)](https://travis-ci.org/NoBetterThan97/FoodNutritionix)
4
+
3
5
  :hammer: Everything from scratch
@@ -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'
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
  module FoodNutritionix
3
3
  class Food
4
- attr_reader :name,
5
- :serving_quantity,
6
- :serving_unit,
7
- :serving_weight,
8
- :calories,
9
- :total_fat,
10
- :saturated_fat,
11
- :cholesterol,
12
- :sodium,
13
- :carbohydrate,
14
- :dietary_fiber,
15
- :sugars,
16
- :protein,
17
- :potassium,
18
- :photo
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
@@ -13,7 +13,6 @@ module FoodNutritionix
13
13
  end
14
14
 
15
15
  def self.config
16
- return @config if @config
17
16
  @config ||= { x_app_id: ENV['X_APP_ID'], x_app_key: ENV['X_APP_KEY'] }
18
17
  end
19
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FoodNutritionix
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ require_relative '../lib/foodnutritionix.rb'
14
14
  Dotenv.load
15
15
 
16
16
  CASSETTES_FOLDER = 'spec/support/cassettes'
17
- FOODS = ['pizza']
17
+ FOODS = ['pizza'].freeze
18
18
 
19
19
  VCR.configure do |config|
20
20
  config.cassette_library_dir = CASSETTES_FOLDER
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.3
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-06 00:00:00.000000000 Z
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: minitest
42
+ name: flog
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.9'
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: '5.9'
54
+ version: '4.4'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest-rg
56
+ name: flay
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.2'
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: '5.2'
68
+ version: '2.8'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '11.3'
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: '11.3'
82
+ version: '0.14'
83
83
  - !ruby/object:Gem::Dependency
84
- name: vcr
84
+ name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
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: '3.0'
96
+ version: '5.9'
97
97
  - !ruby/object:Gem::Dependency
98
- name: webmock
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.1'
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.1'
110
+ version: '5.2'
111
111
  - !ruby/object:Gem::Dependency
112
- name: simplecov
112
+ name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.12'
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: '0.12'
124
+ version: '11.3'
125
125
  - !ruby/object:Gem::Dependency
126
- name: flog
126
+ name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '4.4'
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: '4.4'
138
+ version: '0.42'
139
139
  - !ruby/object:Gem::Dependency
140
- name: flay
140
+ name: vcr
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '2.8'
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: '2.8'
152
+ version: '3.0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: rubocop
154
+ name: webmock
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0.42'
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: '0.42'
166
+ version: '2.1'
167
167
  - !ruby/object:Gem::Dependency
168
- name: httparty
168
+ name: simplecov
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.14'
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.14'
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