food_info 0.0.3 → 0.0.4
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.
- data/HISTORY.markdown +4 -0
- data/lib/food_info.rb +10 -3
- data/lib/food_info/adapters/fat_secret.rb +1 -0
- data/lib/food_info/adapters/fat_secret/data/food_item.rb +5 -1
- data/lib/food_info/adapters/fat_secret/data/search_results.rb +6 -0
- data/lib/food_info/cache_adapters/mem_cache.rb +7 -0
- data/lib/food_info/utils.rb +2 -0
- data/lib/food_info/version.rb +1 -1
- metadata +75 -44
data/HISTORY.markdown
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.0.4 September 26, 2011
|
4
|
+
* API improvement: Can index directly into search results (e.g. FoodInfo.search('a')[3])
|
5
|
+
* Bugfix: FoodInfo.details('..') now correctly handles results with only one serving returned
|
6
|
+
|
3
7
|
## 0.0.3 September 12, 2011
|
4
8
|
* Added missing gem dependency on ruby-hmac
|
5
9
|
|
data/lib/food_info.rb
CHANGED
@@ -28,17 +28,24 @@ module FoodInfo
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def search(q, opts = {})
|
31
|
-
next_adapter.search(q, opts)
|
31
|
+
cached(:search, q, opts) { next_adapter.search(q, opts) }
|
32
32
|
end
|
33
33
|
|
34
34
|
def details(id)
|
35
|
-
next_adapter.details(id)
|
35
|
+
cached(:details, id) { next_adapter.details(id) }
|
36
36
|
end
|
37
37
|
|
38
38
|
|
39
|
+
|
40
|
+
|
41
|
+
def cached(method, param, opts = {}, &block)
|
42
|
+
# TODO - implement caching strategy
|
43
|
+
block.call
|
44
|
+
end
|
45
|
+
|
39
46
|
# FUTURE: This connection pool code won't do much good until HTTParty is non-blocking
|
40
47
|
def next_adapter
|
41
|
-
raise NoAdapterSpecified.new("You must run FoodInfo.establish_connection first") unless @@pool
|
48
|
+
raise NoAdapterSpecified.new("You must run FoodInfo.establish_connection first") unless defined?(@@pool)
|
42
49
|
@@cursor = (@@cursor + 1) % @@pool.length
|
43
50
|
@@pool[@@cursor]
|
44
51
|
end
|
@@ -13,7 +13,11 @@ module FoodInfo
|
|
13
13
|
|
14
14
|
def initialize(*args)
|
15
15
|
super(*args)
|
16
|
-
|
16
|
+
|
17
|
+
# Can't use Array(), as that turns internals of the hash into array pairs as well
|
18
|
+
serving_info = self[:servings]['serving']
|
19
|
+
serving_info = [serving_info] if serving_info.is_a?(Hash)
|
20
|
+
self[:servings] = serving_info.collect{|s| FoodServing.new(s) }
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -31,6 +31,12 @@ module FoodInfo
|
|
31
31
|
self[:results].each{|result| block.call(result)}
|
32
32
|
end
|
33
33
|
|
34
|
+
# Allows pulling out a specific index without having to call results -- search('cheese')[3], not search('cheese').results[3]
|
35
|
+
def [](idx)
|
36
|
+
super(idx) if idx.is_a?(Symbol) || idx.to_i.zero?
|
37
|
+
self[:results][idx]
|
38
|
+
end
|
39
|
+
|
34
40
|
end
|
35
41
|
|
36
42
|
end
|
data/lib/food_info/utils.rb
CHANGED
data/lib/food_info/version.rb
CHANGED
metadata
CHANGED
@@ -1,58 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: food_info
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Kali Donovan
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2011-09-26 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: httparty
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 13
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 7
|
32
|
+
- 7
|
21
33
|
version: 0.7.7
|
22
34
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
26
37
|
name: hashie
|
27
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
40
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 19
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 1
|
48
|
+
- 0
|
32
49
|
version: 1.1.0
|
33
50
|
type: :runtime
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
37
53
|
name: ruby-hmac
|
38
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
56
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
44
64
|
type: :runtime
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
is modular so other adapters can be plugged in, but only data source currently implemented
|
49
|
-
is FatSecret.
|
50
|
-
email:
|
65
|
+
version_requirements: *id003
|
66
|
+
description: Generic Ruby interface to look up nutritional information on food. Design is modular so other adapters can be plugged in, but only data source currently implemented is FatSecret.
|
67
|
+
email:
|
51
68
|
- kali@deviantech.com
|
52
69
|
executables: []
|
70
|
+
|
53
71
|
extensions: []
|
72
|
+
|
54
73
|
extra_rdoc_files: []
|
55
|
-
|
74
|
+
|
75
|
+
files:
|
56
76
|
- .gitignore
|
57
77
|
- Gemfile
|
58
78
|
- HISTORY.markdown
|
@@ -69,31 +89,42 @@ files:
|
|
69
89
|
- lib/food_info/adapters/fat_secret/data/search_result.rb
|
70
90
|
- lib/food_info/adapters/fat_secret/data/search_results.rb
|
71
91
|
- lib/food_info/adapters/fat_secret/request.rb
|
92
|
+
- lib/food_info/cache_adapters/mem_cache.rb
|
72
93
|
- lib/food_info/errors.rb
|
73
94
|
- lib/food_info/utils.rb
|
74
95
|
- lib/food_info/version.rb
|
75
96
|
homepage: https://github.com/deviantech/food_info
|
76
97
|
licenses: []
|
98
|
+
|
77
99
|
post_install_message:
|
78
100
|
rdoc_options: []
|
79
|
-
|
101
|
+
|
102
|
+
require_paths:
|
80
103
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
105
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
114
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
93
122
|
requirements: []
|
123
|
+
|
94
124
|
rubyforge_project:
|
95
125
|
rubygems_version: 1.8.10
|
96
126
|
signing_key:
|
97
127
|
specification_version: 3
|
98
128
|
summary: API for researching nutritional information of various foods
|
99
129
|
test_files: []
|
130
|
+
|