datapackage 0.3.1 → 0.4.0
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/README.md +10 -7
- data/lib/datapackage/resource.rb +37 -1
- data/lib/datapackage/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24359f31d78a11bb84030f328d756d2eeeddf3ff
|
4
|
+
data.tar.gz: 66bf2e40772e87ddb61278934ecfa89bcacd19c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 003a61b6fe90164f3ade94ebd60c203ca7391f983a3b8fe3dc919bbbfefae50e95bbc2de8262f555dd1a15b5d12921f21f55be23c115426ecc12ebf7d383c24b
|
7
|
+
data.tar.gz: 02f13d64df668a0f532bb4d28ec11714dca9086fbc0771eb3e083dcb28992eb7644b743380425fa04b7bf4c6ae282eca8cbc1329951a9678ee90c57816e94f9a
|
data/README.md
CHANGED
@@ -108,20 +108,23 @@ first_resource.tabular?
|
|
108
108
|
first_resource.source
|
109
109
|
```
|
110
110
|
|
111
|
-
You can then read the source depending on its
|
111
|
+
You can then read the source depending on its type. For example if resource is local and not multipart it could by open as a file: `File.open(resource.source)`.
|
112
112
|
|
113
113
|
If a resource complies with the [Tabular Data Resource spec](https://specs.frictionlessdata.io/tabular-data-resource/) or uses the
|
114
|
-
`tabular-data-resource` [profile](#profiles) you can
|
114
|
+
`tabular-data-resource` [profile](#profiles) you can read resource rows:
|
115
115
|
|
116
116
|
```ruby
|
117
|
-
package.resources[0]
|
118
|
-
|
117
|
+
resoure = package.resources[0]
|
118
|
+
resource.tabular?
|
119
|
+
resource.headers
|
120
|
+
resource.schema
|
119
121
|
|
120
|
-
# Read the
|
121
|
-
data =
|
122
|
+
# Read the the whole rows at once
|
123
|
+
data = resource.read
|
124
|
+
data = resource.read(keyed: true)
|
122
125
|
|
123
126
|
# Or iterate through it
|
124
|
-
data =
|
127
|
+
data = resource.iter {|row| print row}
|
125
128
|
```
|
126
129
|
|
127
130
|
See [TableSchema](https://github.com/frictionlessdata/tableschema-rb) documentation for other things you can do with tabular resource.
|
data/lib/datapackage/resource.rb
CHANGED
@@ -67,8 +67,40 @@ module DataPackage
|
|
67
67
|
|
68
68
|
alias :tabular :tabular?
|
69
69
|
|
70
|
+
def headers
|
71
|
+
if !tabular
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
get_table.headers
|
75
|
+
end
|
76
|
+
|
77
|
+
def schema
|
78
|
+
if !tabular
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
get_table.schema
|
82
|
+
end
|
83
|
+
|
84
|
+
def iter(*args, &block)
|
85
|
+
if !tabular
|
86
|
+
message ='Methods iter/read are not supported for non tabular data'
|
87
|
+
raise ResourceException.new message
|
88
|
+
end
|
89
|
+
get_table.iter(*args, &block)
|
90
|
+
end
|
91
|
+
|
92
|
+
def read(*args, &block)
|
93
|
+
if !tabular
|
94
|
+
message ='Methods iter/read are not supported for non tabular data'
|
95
|
+
raise ResourceException.new message
|
96
|
+
end
|
97
|
+
get_table.read(*args, &block)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Deprecated
|
101
|
+
|
70
102
|
def table
|
71
|
-
|
103
|
+
get_table
|
72
104
|
end
|
73
105
|
|
74
106
|
# Private
|
@@ -90,6 +122,10 @@ module DataPackage
|
|
90
122
|
end
|
91
123
|
end
|
92
124
|
|
125
|
+
def get_table
|
126
|
+
@table ||= TableSchema::Table.new(self.source, self['schema']) if tabular?
|
127
|
+
end
|
128
|
+
|
93
129
|
def apply_defaults!
|
94
130
|
self['profile'] ||= DataPackage::DEFAULTS[:resource][:profile]
|
95
131
|
self['encoding'] ||= DataPackage::DEFAULTS[:resource][:encoding]
|
data/lib/datapackage/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
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: 2017-08-
|
13
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json-schema
|