datapackage 0.1.0 → 0.1.1

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: 0dbfa361366c6830bb4624347821cc07c754d903
4
- data.tar.gz: 4fc8b53abca06e6885d686cde540a21ad591aa49
3
+ metadata.gz: ce6f0ffb39c4ee1207b70385a35ae6ffdefac062
4
+ data.tar.gz: dc57cbe51b6546650c94b434f890292d7bf30513
5
5
  SHA512:
6
- metadata.gz: 53d75e66e0b49d2a92350d826f8e33e371f76b162fd8c94ecccf566064aa3e0e5c6f98aa2ec89deafa7126a359d804383df03163e91035721f7f4c22efcbcda9
7
- data.tar.gz: 4e4b96bef09d7e46f06e7eac048ebacf45aebf3bcb50a6b9f44bf1ff578e7153fc49e5cb64239b76d84a6c936128c5e8394d2f50c67de25203565f0d997cc7df
6
+ metadata.gz: 941fd655c6abdb97df01b9de866b346f949d93d7496d5487691dcdf400d6eeacef5ed01eb1ae1dcf6ac69c8d3f7b6fb6b42ce228aad2af1a31d77ce04a4fadaf
7
+ data.tar.gz: a5a5418a64ba0feebd5dc1719546cca54460db1d7c8d8ad8b7b30aaa175316c1bf517130bc85a41f039959a7e12e0436e66669c749562878421853366fdb206a
data/README.md CHANGED
@@ -33,7 +33,7 @@ gem install datapackage
33
33
  Require the gem, if you need to:
34
34
 
35
35
  ```ruby
36
- require 'datapackage.rb'
36
+ require 'datapackage'
37
37
  ```
38
38
 
39
39
  Parsing a Data Package from a remote location:
@@ -66,6 +66,32 @@ package.homepage
66
66
  package.license
67
67
  ```
68
68
 
69
+ ## Reading a Data Package and its resources
70
+
71
+ ```ruby
72
+ require 'datapackage'
73
+
74
+ dp = DataPackage::Package.new('http://data.okfn.org/data/core/gdp/datapackage.json')
75
+
76
+ data = CSV.parse(dp.resources[0].data, headers: true)
77
+ brazil_gdp = data.select { |r| r["Country Code"] == "BRA" }.
78
+ map { |row| { year: Integer(row["Year"]), value: Float(row['Value']) } }
79
+
80
+ max_gdp = brazil_gdp.max_by { |r| r[:value] }
81
+ min_gdp = brazil_gdp.min_by { |r| r[:value] }
82
+
83
+ percentual_increase = (max_gdp[:value] / min_gdp[:value]).round(2)
84
+ max_gdp_val = max_gdp[:value].to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
85
+
86
+ msg = "The highest Brazilian GDP occured in #{max_gdp[:year]}, when it peaked at US$ " +
87
+ "#{max_gdp_val}. This was #{percentual_increase}% more than its minumum GDP " +
88
+ "in #{min_gdp[:year]}"
89
+
90
+ print msg
91
+
92
+ # The highest Brazilian GDP occured in 2011, when it peaked at US$ 2,615,189,973,181. This was 172.44% more than its minimum GDP in 1960.
93
+ ```
94
+
69
95
  ## Creating a Data Package
70
96
 
71
97
  ```ruby
@@ -38,6 +38,10 @@ module DataPackage
38
38
  return true if base_path.start_with?('http')
39
39
  end
40
40
 
41
+ def table
42
+ @table ||= JsonTableSchema::Table.new(CSV.parse(data), self['schema']) if self['schema']
43
+ end
44
+
41
45
  end
42
46
 
43
47
  class LocalResource < Resource
@@ -1,3 +1,3 @@
1
1
  module DataPackage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/datapackage.rb CHANGED
@@ -7,6 +7,7 @@ require 'json-schema'
7
7
  require 'rest-client'
8
8
  require 'zip'
9
9
  require 'ruby_dig'
10
+ require 'jsontableschema'
10
11
 
11
12
  require 'datapackage/version'
12
13
  require 'datapackage/exceptions'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datapackage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh Dodds
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-13 00:00:00.000000000 Z
13
+ date: 2016-10-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -110,6 +110,20 @@ dependencies:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: jsontableschema
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :runtime
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
113
127
  - !ruby/object:Gem::Dependency
114
128
  name: bundler
115
129
  requirement: !ruby/object:Gem::Requirement
@@ -194,20 +208,6 @@ dependencies:
194
208
  - - ">="
195
209
  - !ruby/object:Gem::Version
196
210
  version: '0'
197
- - !ruby/object:Gem::Dependency
198
- name: henry
199
- requirement: !ruby/object:Gem::Requirement
200
- requirements:
201
- - - ">="
202
- - !ruby/object:Gem::Version
203
- version: '0'
204
- type: :development
205
- prerelease: false
206
- version_requirements: !ruby/object:Gem::Requirement
207
- requirements:
208
- - - ">="
209
- - !ruby/object:Gem::Version
210
- version: '0'
211
211
  description:
212
212
  email:
213
213
  - ops@theodi.org
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  requirements: []
248
248
  rubyforge_project:
249
- rubygems_version: 2.5.1
249
+ rubygems_version: 2.6.6
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: Library for working with data packages