mat 0.0.1 → 0.0.2

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: a9766485afe87dccb42c0ecec87cd259f9b45503
4
- data.tar.gz: 270ab12ccd5262b6f77f84be8e117155f7a33215
3
+ metadata.gz: 4661de4427e8006fece6e12523bdd86e7511a661
4
+ data.tar.gz: 9701f7420de90d675426497a349ce3a0cab0fea2
5
5
  SHA512:
6
- metadata.gz: 295337f809540e33831b43ff7ed360ab626ad272da1fe6344b5732a21bb4fa6f0a04231cd6189a75f1e7c4028245022b32b7602d1595ce0d6e058fbc3d40e234
7
- data.tar.gz: 12d167649edeba0ab5e00716bf5a53ddd029b3d22045e6db966db8dc79f039f4a02f1862d4e2dbf81f000c3b50c9a8f7dedf8bf0f1185b7c52755711170a4bed
6
+ metadata.gz: e22976351959a023dac8b9d91534e136f92ba2db22c8181283396c5f8cac055900a45dc8df00cdc36a59843778d7a5df9bb3b4844d0cdb149b0c2d00610e34c2
7
+ data.tar.gz: 084b9d44bf2726c3174f4d4c2c40ea04969121d376adb21cd5ca731edd10fde9be08319370ef3d2bdc007242a929b3ef93fe823c99e55d97dab74b7dad39b31f
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
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
+ [![Build Status](https://travis-ci.org/peterhellberg/mat.png?branch=master)](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
- köttfärspaj = Mat.all('Köttfärs').first
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
- köttfärspaj.iron #=> 1.09
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?
@@ -23,7 +23,7 @@ module Mat
23
23
  end
24
24
 
25
25
  def name
26
- data['name']
26
+ data['name'].to_s.strip
27
27
  end
28
28
 
29
29
  def number
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Mat
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
@@ -1,58 +1,60 @@
1
1
  {
2
2
  "name": "Dressing majonnäs fett ca 40% ",
3
- "foodstuffNumber": 44,
4
- "energyKj": 1898,
5
- "energyKcal": 454,
6
- "protein": 0.5,
7
- "fat": 40,
8
- "carbohydrates": 24,
9
- "fibres": 0.2,
10
- "salt": 1.7,
11
- "ash": 2.1,
12
- "water": 33.2,
13
- "alcohol": 0,
14
- "monosaccharides": 3.1,
15
- "disaccharides": 18.6,
16
- "saccharose": 18.6,
17
- "wholegrain": 0,
18
- "saturatedFattyAcids": 6.1,
19
- "fattyAcid40100": 0,
20
- "fattyAcid120": 0,
21
- "fattyAcid140": 0,
22
- "fattyAcid160": 4.2,
23
- "fattyAcid180": 1.5,
24
- "fattyAcid200": 0.2,
25
- "monounsaturatedFattyAcids": 9.8,
26
- "fattyAcid161": 0,
27
- "fattyAcid181": 9.8,
28
- "sumPolyunsaturatedFattyAcids": 22.3,
29
- "fattyAcid182": 19.7,
30
- "fattyAcid204": 0,
31
- "fattyAcid183": 2.6,
32
- "epa": 0,
33
- "dpa": 0,
34
- "dha": 0,
35
- "cholesterol": 26,
36
- "retinolEquivalents": 2,
37
- "retinol": 2,
38
- "betacarotene": 0,
39
- "vitaminD": 0,
40
- "vitaminE": 2.5,
41
- "timamine": 0.01,
42
- "riboflavin": 0.02,
43
- "vitaminC": 0,
44
- "niacin": 0,
45
- "niacinEquivalents": 0.1,
46
- "vitaminB6": 0.02,
47
- "vitaminB12": 0.2,
48
- "phosphorous": 17,
49
- "folate": 7,
50
- "trash": 0,
51
- "iron": 0.3,
52
- "calcium": 11,
53
- "potassium": 142,
54
- "magnesium": 5,
55
- "sodium": 680,
56
- "selenium": 0.5,
57
- "zink": 0.1
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
  }
@@ -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
@@ -12,7 +12,7 @@ describe Mat do
12
12
  api.config.base_url.must_equal "api.test"
13
13
  end
14
14
 
15
- it "memoizes the api client" do
15
+ it "does not memoize the api client" do
16
16
  subject.api.object_id.wont_equal subject.api.object_id
17
17
  end
18
18
 
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.1
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 00:00:00.000000000 Z
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