food_info 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.5 September 26, 2011
4
+ * Bugfix: missing 'return' was wreaking havoc with FoodInfo.search
5
+
3
6
  ## 0.0.4 September 26, 2011
4
7
  * API improvement: Can index directly into search results (e.g. FoodInfo.search('a')[3])
5
8
  * Bugfix: FoodInfo.details('..') now correctly handles results with only one serving returned
data/lib/food_info.rb CHANGED
@@ -28,11 +28,11 @@ module FoodInfo
28
28
  end
29
29
 
30
30
  def search(q, opts = {})
31
- cached(:search, q, opts) { next_adapter.search(q, opts) }
31
+ cached(:search, q, opts)
32
32
  end
33
33
 
34
- def details(id)
35
- cached(:details, id) { next_adapter.details(id) }
34
+ def details(id, opts = {})
35
+ cached(:details, id)
36
36
  end
37
37
 
38
38
 
@@ -40,7 +40,7 @@ module FoodInfo
40
40
 
41
41
  def cached(method, param, opts = {}, &block)
42
42
  # TODO - implement caching strategy
43
- block.call
43
+ next_adapter.send(method, param, opts)
44
44
  end
45
45
 
46
46
  # FUTURE: This connection pool code won't do much good until HTTParty is non-blocking
@@ -24,12 +24,12 @@ module FoodInfo
24
24
  }
25
25
  params[:page_number] = [params[:page_number].to_i - 1, 0].max # FatSecret's pagination starts at 0
26
26
  params[:max_results] = [params[:max_results].to_i, 50].min # FatSecret's max allowed results per page
27
-
27
+
28
28
  data = query('foods.search', params)
29
29
  Data::SearchResults.new( data['foods'] )
30
30
  end
31
31
 
32
- def details(food_id)
32
+ def details(food_id, opts = {})
33
33
  data = query('food.get', :food_id => food_id)
34
34
  Data::FoodItem.new( data['food'] )
35
35
  end
@@ -12,14 +12,14 @@ module FoodInfo
12
12
  property :total_results
13
13
 
14
14
  def initialize(*args)
15
- super(*args)
15
+ super(*args)
16
16
  normalize_data
17
17
  end
18
18
 
19
- def normalize_data
19
+ def normalize_data
20
20
  [:page, :per_page, :total_results].each do |n|
21
21
  self[n] = self[n].to_i
22
- end
22
+ end
23
23
 
24
24
  self[:page] += 1 # FatSecret indexes their pages from 0
25
25
  self[:results] = [self[:results]] unless self[:results].is_a?(Array)
@@ -33,7 +33,7 @@ module FoodInfo
33
33
 
34
34
  # Allows pulling out a specific index without having to call results -- search('cheese')[3], not search('cheese').results[3]
35
35
  def [](idx)
36
- super(idx) if idx.is_a?(Symbol) || idx.to_i.zero?
36
+ return super(idx) if idx.is_a?(Symbol) || idx.to_i.zero?
37
37
  self[:results][idx]
38
38
  end
39
39
 
@@ -1,3 +1,3 @@
1
1
  module FoodInfo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,78 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: food_info
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kali Donovan
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: httparty
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70296305209760 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 13
29
- segments:
30
- - 0
31
- - 7
32
- - 7
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.7.7
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: hashie
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70296305209760
25
+ - !ruby/object:Gem::Dependency
26
+ name: hashie
27
+ requirement: &70296305209140 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 19
45
- segments:
46
- - 1
47
- - 1
48
- - 0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
49
32
  version: 1.1.0
50
33
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: ruby-hmac
54
34
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70296305209140
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-hmac
38
+ requirement: &70296305208640 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
64
44
  type: :runtime
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:
45
+ prerelease: false
46
+ version_requirements: *70296305208640
47
+ description: Generic Ruby interface to look up nutritional information on food. Design
48
+ is modular so other adapters can be plugged in, but only data source currently implemented
49
+ is FatSecret.
50
+ email:
68
51
  - kali@deviantech.com
69
52
  executables: []
70
-
71
53
  extensions: []
72
-
73
54
  extra_rdoc_files: []
74
-
75
- files:
55
+ files:
76
56
  - .gitignore
77
57
  - Gemfile
78
58
  - HISTORY.markdown
@@ -95,36 +75,26 @@ files:
95
75
  - lib/food_info/version.rb
96
76
  homepage: https://github.com/deviantech/food_info
97
77
  licenses: []
98
-
99
78
  post_install_message:
100
79
  rdoc_options: []
101
-
102
- require_paths:
80
+ require_paths:
103
81
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
82
+ required_ruby_version: !ruby/object:Gem::Requirement
105
83
  none: false
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
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
89
  none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- hash: 3
119
- segments:
120
- - 0
121
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
122
94
  requirements: []
123
-
124
95
  rubyforge_project:
125
96
  rubygems_version: 1.8.10
126
97
  signing_key:
127
98
  specification_version: 3
128
99
  summary: API for researching nutritional information of various foods
129
100
  test_files: []
130
-