mat 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +10 -5
- data/bin/mat +20 -0
- data/lib/mat/foodstuff.rb +1 -1
- data/lib/mat/version.rb +1 -1
- data/spec/fixtures/foodstuff/44.json +57 -55
- data/spec/mat/foodstuff_spec.rb +36 -0
- data/spec/mat_spec.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4661de4427e8006fece6e12523bdd86e7511a661
|
4
|
+
data.tar.gz: 9701f7420de90d675426497a349ce3a0cab0fea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22976351959a023dac8b9d91534e136f92ba2db22c8181283396c5f8cac055900a45dc8df00cdc36a59843778d7a5df9bb3b4844d0cdb149b0c2d00610e34c2
|
7
|
+
data.tar.gz: 084b9d44bf2726c3174f4d4c2c40ea04969121d376adb21cd5ca731edd10fde9be08319370ef3d2bdc007242a929b3ef93fe823c99e55d97dab74b7dad39b31f
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -4,6 +4,8 @@ A small (unofficial) API client for the [Mat API](http://matapi.se/).
|
|
4
4
|
|
5
5
|
The documentation is in Swedish, but so is the [data](http://www.slv.se/sv/grupp1/mat-och-naring/vad-innehaller-maten/livsmedelsdatabasen-/).
|
6
6
|
|
7
|
+
[](https://travis-ci.org/peterhellberg/mat)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -23,18 +25,21 @@ Or install it yourself as:
|
|
23
25
|
It is probably a good idea to take a look in `specs`
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
# All nutrients
|
27
|
-
Mat.nutrients
|
28
|
-
|
29
28
|
# Find the first food with ’köttfärs’ in the name
|
30
|
-
|
29
|
+
food = Mat.all('Köttfärs').first
|
30
|
+
|
31
|
+
# You can also pass a search query to the find method
|
32
|
+
food = Mat.find('Köttfärs')
|
31
33
|
|
32
34
|
# Get the `iron` value
|
33
|
-
|
35
|
+
food.iron #=> 1.09
|
34
36
|
|
35
37
|
# Find a specific food by its number
|
36
38
|
food = Mat.find(3)
|
37
39
|
food.name #=> "Ister gris"
|
40
|
+
|
41
|
+
# You can also list all nutrients
|
42
|
+
Mat.nutrients
|
38
43
|
```
|
39
44
|
|
40
45
|
## Contributing
|
data/bin/mat
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mat'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
def get_data(query)
|
7
|
+
if query.match(/^\d+$/)
|
8
|
+
Mat.api.foodstuff(query)
|
9
|
+
else
|
10
|
+
Mat.api.foodstuffs(query)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def search(query)
|
15
|
+
puts JSON.pretty_generate get_data(query)
|
16
|
+
rescue Mat::HTTP::Exception
|
17
|
+
warn "Nothing found"
|
18
|
+
end
|
19
|
+
|
20
|
+
search(ARGV.first) if ARGV.any?
|
data/lib/mat/foodstuff.rb
CHANGED
data/lib/mat/version.rb
CHANGED
@@ -1,58 +1,60 @@
|
|
1
1
|
{
|
2
2
|
"name": "Dressing majonnäs fett ca 40% ",
|
3
|
-
"
|
4
|
-
"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
3
|
+
"number": 44,
|
4
|
+
"nutrientValues": {
|
5
|
+
"energyKj": 1898,
|
6
|
+
"energyKcal": 454,
|
7
|
+
"protein": 0.5,
|
8
|
+
"fat": 40,
|
9
|
+
"carbohydrates": 24,
|
10
|
+
"fibres": 0.2,
|
11
|
+
"salt": 1.7,
|
12
|
+
"ash": 2.1,
|
13
|
+
"water": 33.2,
|
14
|
+
"alcohol": 0,
|
15
|
+
"monosaccharides": 3.1,
|
16
|
+
"disaccharides": 18.6,
|
17
|
+
"saccharose": 18.6,
|
18
|
+
"wholegrain": 0,
|
19
|
+
"saturatedFattyAcids": 6.1,
|
20
|
+
"fattyAcid40100": 0,
|
21
|
+
"fattyAcid120": 0,
|
22
|
+
"fattyAcid140": 0,
|
23
|
+
"fattyAcid160": 4.2,
|
24
|
+
"fattyAcid180": 1.5,
|
25
|
+
"fattyAcid200": 0.2,
|
26
|
+
"monounsaturatedFattyAcids": 9.8,
|
27
|
+
"fattyAcid161": 0,
|
28
|
+
"fattyAcid181": 9.8,
|
29
|
+
"sumPolyunsaturatedFattyAcids": 22.3,
|
30
|
+
"fattyAcid182": 19.7,
|
31
|
+
"fattyAcid204": 0,
|
32
|
+
"fattyAcid183": 2.6,
|
33
|
+
"epa": 0,
|
34
|
+
"dpa": 0,
|
35
|
+
"dha": 0,
|
36
|
+
"cholesterol": 26,
|
37
|
+
"retinolEquivalents": 2,
|
38
|
+
"retinol": 2,
|
39
|
+
"betacarotene": 0,
|
40
|
+
"vitaminD": 0,
|
41
|
+
"vitaminE": 2.5,
|
42
|
+
"timamine": 0.01,
|
43
|
+
"riboflavin": 0.02,
|
44
|
+
"vitaminC": 0,
|
45
|
+
"niacin": 0,
|
46
|
+
"niacinEquivalents": 0.1,
|
47
|
+
"vitaminB6": 0.02,
|
48
|
+
"vitaminB12": 0.2,
|
49
|
+
"phosphorous": 17,
|
50
|
+
"folate": 7,
|
51
|
+
"trash": 0,
|
52
|
+
"iron": 0.3,
|
53
|
+
"calcium": 11,
|
54
|
+
"potassium": 142,
|
55
|
+
"magnesium": 5,
|
56
|
+
"sodium": 680,
|
57
|
+
"selenium": 0.5,
|
58
|
+
"zink": 0.1
|
59
|
+
}
|
58
60
|
}
|
data/spec/mat/foodstuff_spec.rb
CHANGED
@@ -14,4 +14,40 @@ describe Mat::Foodstuff do
|
|
14
14
|
subject.new("foo").data.must_equal "foo"
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
describe "name" do
|
19
|
+
it "returns the name from the data" do
|
20
|
+
foodstuff.name.must_equal "Dressing majonnäs fett ca 40%"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "number" do
|
25
|
+
it "returns the number from the data" do
|
26
|
+
foodstuff.number.must_equal 44
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "nutrient_values" do
|
31
|
+
it "returns the nutrient values for the food" do
|
32
|
+
foodstuff.nutrient_values['energyKj'].must_equal 1898
|
33
|
+
end
|
34
|
+
|
35
|
+
it "it retrieves more data if needed" do
|
36
|
+
food = subject.new("number" => 44)
|
37
|
+
|
38
|
+
Mat.api.stub(:foodstuff, fixture_data) do
|
39
|
+
food.nutrient_values['energyKj'].must_equal 1898
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "get_data!" do
|
45
|
+
it "retrieves more data" do
|
46
|
+
food = subject.new("number" => 44)
|
47
|
+
|
48
|
+
Mat.api.stub(:foodstuff, fixture_data) do
|
49
|
+
food.get_data!.zink.must_equal 0.1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
17
53
|
end
|
data/spec/mat_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Hellberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,15 +69,18 @@ dependencies:
|
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- peter@c7.se
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- mat
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
76
77
|
- .gitignore
|
78
|
+
- .travis.yml
|
77
79
|
- Gemfile
|
78
80
|
- LICENSE.txt
|
79
81
|
- README.md
|
80
82
|
- Rakefile
|
83
|
+
- bin/mat
|
81
84
|
- lib/mat.rb
|
82
85
|
- lib/mat/api.rb
|
83
86
|
- lib/mat/api/config.rb
|