datapackage 0.2.6 → 0.3.1

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: 18b6d480843853daa822de909d242c78b40ed762
4
- data.tar.gz: 4c6004ea6559656434a5759038cc0163c0762520
3
+ metadata.gz: b986907d114eedf9c0de5138f42b50934f249d7c
4
+ data.tar.gz: 0a011fae8e6e404b6ca5df4ae1bd878056523930
5
5
  SHA512:
6
- metadata.gz: e3c5286265b393c7c7ecd3563515bccfb67f2c20a54b6c15e2d4ad1ac00f6c55b69f18c591e38397958a6bf23cd9d0c88deda81ae39e06cf6d8532607f31eeda
7
- data.tar.gz: d09058baf930fda7eb99d688f9c9fb405bc1910563d0b1e48763400dc877c27a1540c69eb24e292827e511500612156b37022cbf067622bb2d649fa3e9e9f84b
6
+ metadata.gz: 3f8747b92725b9c94c70dece7dd38e82b93e5e4151b70d94c66faaed4ae121ef055783afc3a0b81ade12e639ddbb59c88a2f985002b0d48581e89327f7690ee6
7
+ data.tar.gz: 4f4fae0f01f0ac90f008f0e76fc4875cc35ad54cb195e870920a5b8fae4f24b5026030201737b6a547a720b39e995406a2a6fa7e6a79cd3ee7e2fee7e0df58b6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DataPackage.rb
1
+ # datapackage-rb
2
2
 
3
3
  [![Travis](https://travis-ci.org/frictionlessdata/datapackage-rb.svg?branch=master)](https://travis-ci.org/frictionlessdata/datapackage-rb)
4
4
  [![Coveralls](http://img.shields.io/coveralls/frictionlessdata/datapackage-rb.svg?branch=master)](https://coveralls.io/r/frictionlessdata/datapackage-rb?branch=master)
@@ -100,7 +100,11 @@ first_resource = package.resources[0]
100
100
  first_resource = package.get_resource('example')
101
101
 
102
102
  # Get info about the data source of this resource
103
- first_resource.source_type
103
+ first_resource.inline?
104
+ first_resource.local?
105
+ first_resource.remote?
106
+ first_resource.multipart?
107
+ first_resource.tabular?
104
108
  first_resource.source
105
109
  ```
106
110
 
@@ -4,7 +4,9 @@ module DataPackage
4
4
  class Package < Hash
5
5
  include DataPackage::Helpers
6
6
 
7
- attr_reader :opts, :errors, :profile, :dead_resources
7
+ # Public
8
+
9
+ attr_reader :errors, :profile
8
10
 
9
11
  # Parse or create a data package
10
12
  # Supports reading data from JSON file, directory, and a URL
@@ -24,41 +26,6 @@ module DataPackage
24
26
  raise PackageException.new 'Package descriptor is not valid JSON'
25
27
  end
26
28
 
27
- def descriptor
28
- self.to_h
29
- end
30
-
31
- # Returns the directory for a local file package or base url for a remote
32
- # Returns nil for an in-memory object (because it has no base as yet)
33
- def base
34
- # user can override base
35
- return @opts[:base] if @opts[:base]
36
- return '' unless @location
37
- # work out base directory or uri
38
- if local?
39
- return File.dirname(@location)
40
- else
41
- return @location.split('/')[0..-2].join('/')
42
- end
43
- end
44
-
45
- # Is this a local package? Returns true if created from an in-memory object or a file/directory reference
46
- def local?
47
- return @local if @local
48
- return false if @location =~ /\A#{URI::regexp}\z/
49
- true
50
- end
51
-
52
- def resources
53
- update_resources!
54
- self['resources']
55
- end
56
-
57
- def resource_names
58
- update_resources!
59
- self['resources'].map{|res| res.name}
60
- end
61
-
62
29
  def valid?
63
30
  return false unless @profile.valid?(self)
64
31
  return false if self['resources'].map{ |resource| resource.valid? }.include?(false)
@@ -81,6 +48,25 @@ module DataPackage
81
48
  errors.each{ |error| yield error }
82
49
  end
83
50
 
51
+ def descriptor
52
+ self.to_h
53
+ end
54
+
55
+ def resources
56
+ update_resources!
57
+ self['resources']
58
+ end
59
+
60
+ def resource_names
61
+ update_resources!
62
+ self['resources'].map{|res| res.name}
63
+ end
64
+
65
+ def get_resource(resource_name)
66
+ update_resources!
67
+ self['resources'].find{ |resource| resource.name == resource_name }
68
+ end
69
+
84
70
  def add_resource(resource)
85
71
  resource = load_resource(resource)
86
72
  self['resources'].push(resource)
@@ -100,21 +86,41 @@ module DataPackage
100
86
  resource
101
87
  end
102
88
 
103
- def get_resource(resource_name)
104
- update_resources!
105
- self['resources'].find{ |resource| resource.name == resource_name }
106
- end
107
-
108
89
  def save(target=@location)
109
90
  update_resources!
110
91
  File.open(target, "w") { |file| file << JSON.pretty_generate(self) }
111
92
  true
112
93
  end
113
94
 
95
+ # Deprecated
96
+
97
+ # Returns the directory for a local file package or base url for a remote
98
+ # Returns nil for an in-memory object (because it has no base as yet)
99
+ def base
100
+ # user can override base
101
+ return @opts[:base] if @opts[:base]
102
+ return '' unless @location
103
+ # work out base directory or uri
104
+ if local?
105
+ return File.dirname(@location)
106
+ else
107
+ return @location.split('/')[0..-2].join('/')
108
+ end
109
+ end
110
+
111
+ # Is this a local package? Returns true if created from an in-memory object or a file/directory reference
112
+ def local?
113
+ return @local if @local
114
+ return false if @location =~ /\A#{URI::regexp}\z/
115
+ true
116
+ end
117
+
114
118
  def property(property, default = nil)
115
119
  self[property] || default
116
120
  end
117
121
 
122
+ # Private
123
+
118
124
  private
119
125
 
120
126
  def define_properties!
@@ -2,7 +2,9 @@ module DataPackage
2
2
  class Profile < Hash
3
3
  include DataPackage::Helpers
4
4
 
5
- attr_reader :name, :registry
5
+ # Public
6
+
7
+ attr_reader :name
6
8
 
7
9
  def initialize(descriptor)
8
10
  unless descriptor.is_a?(String)
@@ -24,13 +26,6 @@ module DataPackage
24
26
  self.to_h
25
27
  end
26
28
 
27
- # Returns true if there are no errors in data, false if there are
28
- def valid?(data)
29
- JSON::Validator.validate(self, data)
30
- end
31
-
32
- alias :valid :valid?
33
-
34
29
  # Validate data against this profile. Returns true or raises DataPackage::ValidationError
35
30
  def validate(data)
36
31
  JSON::Validator.validate!(self, data)
@@ -43,13 +38,22 @@ module DataPackage
43
38
  JSON::Validator.fully_validate(self, data).each{ |error| yield error }
44
39
  end
45
40
 
41
+ # Returns true if there are no errors in data, false if there are
42
+ def valid?(data)
43
+ JSON::Validator.validate(self, data)
44
+ end
45
+
46
+ alias :valid :valid?
47
+
48
+ # Private
49
+
46
50
  private
47
51
 
48
52
  def get_profile_from_registry(descriptor)
49
53
  @registry = DataPackage::Registry.new
50
- profile_metadata = registry.profiles.fetch(descriptor)
54
+ profile_metadata = @registry.profiles.fetch(descriptor)
51
55
  if profile_metadata.fetch('schema_path', nil)
52
- profile_path = join_paths(base_path(registry.path), profile_metadata['schema_path'])
56
+ profile_path = join_paths(base_path(@registry.path), profile_metadata['schema_path'])
53
57
  else
54
58
  profile_path = profile_metadata['schema']
55
59
  end
@@ -2,7 +2,9 @@ module DataPackage
2
2
  class Resource < Hash
3
3
  include DataPackage::Helpers
4
4
 
5
- attr_reader :name, :profile, :source, :source_type, :errors
5
+ # Public
6
+
7
+ attr_reader :errors, :profile, :name, :source
6
8
 
7
9
  def initialize(resource, base_path = '')
8
10
  self.merge! dereference_descriptor(resource, base_path: base_path,
@@ -14,14 +16,48 @@ module DataPackage
14
16
  apply_table_defaults! if self.tabular?
15
17
  end
16
18
 
19
+ def valid?
20
+ @profile.valid?(self)
21
+ end
22
+
23
+ alias :valid :valid?
24
+
25
+ def validate
26
+ @profile.validate(self)
27
+ end
28
+
29
+ def iter_errors
30
+ @profile.iter_errors(self){ |err| yield err }
31
+ end
32
+
17
33
  def descriptor
18
34
  self.to_h
19
35
  end
20
36
 
21
- def table
22
- @table ||= TableSchema::Table.new(self.source, self['schema']) if tabular?
37
+ def inline?
38
+ @source_type == 'inline'
23
39
  end
24
40
 
41
+ alias :inline :inline?
42
+
43
+ def local?
44
+ @source_type == 'local'
45
+ end
46
+
47
+ alias :local :local?
48
+
49
+ def remote?
50
+ @source_type == 'remote'
51
+ end
52
+
53
+ alias :remote :remote?
54
+
55
+ def miltipart?
56
+ false
57
+ end
58
+
59
+ alias :miltipart :miltipart?
60
+
25
61
  def tabular?
26
62
  tabular_profile = DataPackage::DEFAULTS[:resource][:tabular_profile]
27
63
  return true if @profile.name == tabular_profile
@@ -31,19 +67,11 @@ module DataPackage
31
67
 
32
68
  alias :tabular :tabular?
33
69
 
34
- def valid?
35
- @profile.valid?(self)
36
- end
37
-
38
- alias :valid :valid?
39
-
40
- def validate
41
- @profile.validate(self)
70
+ def table
71
+ @table ||= TableSchema::Table.new(self.source, self['schema']) if tabular?
42
72
  end
43
73
 
44
- def iter_errors
45
- @profile.iter_errors(self){ |err| yield err }
46
- end
74
+ # Private
47
75
 
48
76
  private
49
77
 
@@ -75,12 +103,12 @@ module DataPackage
75
103
  field_descriptor['format'] ||= DataPackage::DEFAULTS[:schema][:format]
76
104
  end
77
105
  end
78
-
79
106
  if self.fetch('dialect', nil)
80
107
  DataPackage::DEFAULTS[:dialect].each do |key, val|
81
108
  self['dialect'][key.to_s] ||= val
82
109
  end
83
110
  end
84
111
  end
112
+
85
113
  end
86
114
  end
@@ -1,3 +1,3 @@
1
1
  module DataPackage
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -538,4 +538,4 @@
538
538
  ]
539
539
  }
540
540
  }
541
- }
541
+ }
@@ -275,4 +275,4 @@
275
275
  ]
276
276
  }
277
277
  }
278
- }
278
+ }
@@ -459,7 +459,7 @@
459
459
  "bareNumber": {
460
460
  "type": "boolean",
461
461
  "title": "bareNumber",
462
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
462
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
463
463
  "default": true
464
464
  },
465
465
  "decimalChar": {
@@ -588,7 +588,7 @@
588
588
  "bareNumber": {
589
589
  "type": "boolean",
590
590
  "title": "bareNumber",
591
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
591
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
592
592
  "default": true
593
593
  },
594
594
  "constraints": {
@@ -2462,7 +2462,7 @@
2462
2462
  "bareNumber": {
2463
2463
  "type": "boolean",
2464
2464
  "title": "bareNumber",
2465
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
2465
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
2466
2466
  "default": true
2467
2467
  },
2468
2468
  "decimalChar": {
@@ -2591,7 +2591,7 @@
2591
2591
  "bareNumber": {
2592
2592
  "type": "boolean",
2593
2593
  "title": "bareNumber",
2594
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
2594
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
2595
2595
  "default": true
2596
2596
  },
2597
2597
  "constraints": {
@@ -4358,4 +4358,4 @@
4358
4358
  }
4359
4359
  }
4360
4360
  ]
4361
- }
4361
+ }
@@ -41,4 +41,4 @@
41
41
  "schema_path": "table-schema.json",
42
42
  "specification": "https://specs.frictionlessdata.io/table-schema/"
43
43
  }
44
- ]
44
+ ]
@@ -155,7 +155,7 @@
155
155
  "bareNumber": {
156
156
  "type": "boolean",
157
157
  "title": "bareNumber",
158
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
158
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
159
159
  "default": true
160
160
  },
161
161
  "decimalChar": {
@@ -284,7 +284,7 @@
284
284
  "bareNumber": {
285
285
  "type": "boolean",
286
286
  "title": "bareNumber",
287
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
287
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
288
288
  "default": true
289
289
  },
290
290
  "constraints": {
@@ -1557,4 +1557,4 @@
1557
1557
  "examples": [
1558
1558
  "{\n \"schema\": {\n \"fields\": [\n {\n \"name\": \"first_name\",\n \"type\": \"string\"\n \"constraints\": {\n \"required\": true\n }\n },\n {\n \"name\": \"age\",\n \"type\": \"integer\"\n },\n ],\n \"primaryKey\": [\n \"name\"\n ]\n }\n}\n"
1559
1559
  ]
1560
- }
1560
+ }
@@ -454,7 +454,7 @@
454
454
  "bareNumber": {
455
455
  "type": "boolean",
456
456
  "title": "bareNumber",
457
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
457
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
458
458
  "default": true
459
459
  },
460
460
  "decimalChar": {
@@ -583,7 +583,7 @@
583
583
  "bareNumber": {
584
584
  "type": "boolean",
585
585
  "title": "bareNumber",
586
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
586
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
587
587
  "default": true
588
588
  },
589
589
  "constraints": {
@@ -2196,4 +2196,4 @@
2196
2196
  ]
2197
2197
  }
2198
2198
  }
2199
- }
2199
+ }
@@ -247,7 +247,7 @@
247
247
  "bareNumber": {
248
248
  "type": "boolean",
249
249
  "title": "bareNumber",
250
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
250
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
251
251
  "default": true
252
252
  },
253
253
  "decimalChar": {
@@ -376,7 +376,7 @@
376
376
  "bareNumber": {
377
377
  "type": "boolean",
378
378
  "title": "bareNumber",
379
- "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
379
+ "description": "a boolean field with a default of `true`. If `true` the physical contents of this field must follow the formatting constraints already set out. If `false` the contents of this field may contain leading and/or trailing non-numeric characters (which implementors MUST therefore strip). The purpose of `bareNumber` is to allow publishers to publish numeric data that contains trailing characters such as percentages e.g. `95%` or leading characters such as currencies e.g. `€95` or `EUR 95`. Note that it is entirely up to implementors what, if anything, they do with stripped text.",
380
380
  "default": true
381
381
  },
382
382
  "constraints": {
@@ -1933,4 +1933,4 @@
1933
1933
  ]
1934
1934
  }
1935
1935
  }
1936
- }
1936
+ }
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.2.6
4
+ version: 0.3.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: 2017-08-28 00:00:00.000000000 Z
13
+ date: 2017-08-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json-schema