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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b986907d114eedf9c0de5138f42b50934f249d7c
4
- data.tar.gz: 0a011fae8e6e404b6ca5df4ae1bd878056523930
3
+ metadata.gz: 24359f31d78a11bb84030f328d756d2eeeddf3ff
4
+ data.tar.gz: 66bf2e40772e87ddb61278934ecfa89bcacd19c4
5
5
  SHA512:
6
- metadata.gz: 3f8747b92725b9c94c70dece7dd38e82b93e5e4151b70d94c66faaed4ae121ef055783afc3a0b81ade12e639ddbb59c88a2f985002b0d48581e89327f7690ee6
7
- data.tar.gz: 4f4fae0f01f0ac90f008f0e76fc4875cc35ad54cb195e870920a5b8fae4f24b5026030201737b6a547a720b39e995406a2a6fa7e6a79cd3ee7e2fee7e0df58b6
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 `source_type`: `inline`, `remote` or `local`.
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 make a [TableSchema::Table](https://github.com/frictionlessdata/tableschema-rb) for it:
114
+ `tabular-data-resource` [profile](#profiles) you can read resource rows:
115
115
 
116
116
  ```ruby
117
- package.resources[0].tabular?
118
- table = package.resources[0].table
117
+ resoure = package.resources[0]
118
+ resource.tabular?
119
+ resource.headers
120
+ resource.schema
119
121
 
120
- # Read the entire table at once
121
- data = table.read
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 = table.iter {|row| print row}
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.
@@ -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
- @table ||= TableSchema::Table.new(self.source, self['schema']) if tabular?
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]
@@ -1,3 +1,3 @@
1
1
  module DataPackage
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.1
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-29 00:00:00.000000000 Z
13
+ date: 2017-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json-schema