data_package 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/lib/attr_helper.rb +28 -18
- data/lib/data_package/field.rb +2 -0
- data/lib/data_package/package.rb +7 -1
- data/lib/data_package/resource.rb +2 -13
- data/lib/data_package/schema.rb +6 -0
- data/lib/data_package/version.rb +1 -1
- data/spec/data_package/package_spec.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: c32d939169849aa526e542b913a074a24c0d3b5e
|
4
|
+
data.tar.gz: daf0cab3aa5f972ba928b38a0911c27ac09630fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65364b7354d36d78ef635296f962ed17ce46d96baa06055df885419b41e9e3e229d1230de01d26371b0ef90095d74133333a6d8fdfe83def2d45280cce557e8
|
7
|
+
data.tar.gz: 1345fe372c3cbed0a53a933989847804276d6d3cb127eb55f6e042a5e4cf36efc8341b1183801f65c713127daf0e85dee3040f6c364da6fd510b39bd823e94bf
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@ Library of classes and utilities for reading and writing data packages
|
|
7
7
|
|
8
8
|
#### Usage
|
9
9
|
|
10
|
+
```
|
10
11
|
attr_required :name
|
11
12
|
attr_required :path, :if => lamda {|obj|
|
12
13
|
obj.attr_missing?(:url) && obj.attr_missing?(:data)
|
@@ -15,18 +16,20 @@ attr_required :path, :if => lamda {|obj|
|
|
15
16
|
attr_optional :title
|
16
17
|
attr_optional :sources, :default => [], :key => 'sources',
|
17
18
|
:serialize => lambda { |source| source.collect(&:to_hash) }
|
19
|
+
```
|
18
20
|
|
19
21
|
key is not required for attr_optional as it defaults to name of the attribute
|
20
22
|
|
21
23
|
#### Instance Methods
|
22
24
|
|
25
|
+
```
|
23
26
|
required_attrs => [...]
|
24
27
|
optional_attrs => [...]
|
25
|
-
|
28
|
+
```
|
26
29
|
|
30
|
+
```
|
27
31
|
attr_required?(attr_name) #=> boolean
|
28
|
-
|
29
|
-
valid? #=> boolean, Are all required fields present?
|
30
|
-
|
31
32
|
attr_missing?(attr_name) #=> boolean
|
32
|
-
attr_present?(attr_name) #=> boolean
|
33
|
+
attr_present?(attr_name) #=> boolean
|
34
|
+
valid? #=> boolean, Are all required fields present?
|
35
|
+
```
|
data/lib/attr_helper.rb
CHANGED
@@ -15,27 +15,11 @@ module AttrHelper
|
|
15
15
|
# that child classes can override
|
16
16
|
|
17
17
|
unless required_attributes.empty?
|
18
|
-
|
19
|
-
klass.attr_required attribute.name, {
|
20
|
-
:name => attribute.name,
|
21
|
-
:key => attribute.key,
|
22
|
-
:default => attribute.default,
|
23
|
-
:serialize => attribute.serialize,
|
24
|
-
:if => attribute.if_cond,
|
25
|
-
:unless => attribute.unless_cond
|
26
|
-
}
|
27
|
-
end
|
18
|
+
add_required_attrs(klass)
|
28
19
|
end
|
29
20
|
|
30
21
|
unless optional_attributes.empty?
|
31
|
-
|
32
|
-
klass.attr_optional attribute.name, {
|
33
|
-
:name => attribute.name,
|
34
|
-
:key => attribute.key,
|
35
|
-
:default => attribute.default,
|
36
|
-
:serialize => attribute.serialize
|
37
|
-
}
|
38
|
-
end
|
22
|
+
add_optional_attrs(klass)
|
39
23
|
end
|
40
24
|
end
|
41
25
|
|
@@ -56,6 +40,32 @@ module AttrHelper
|
|
56
40
|
def required_attributes
|
57
41
|
@required_attributes ||= []
|
58
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def add_required_attrs(klass)
|
47
|
+
required_attributes.each do |attribute|
|
48
|
+
klass.attr_required attribute.name, {
|
49
|
+
:name => attribute.name,
|
50
|
+
:key => attribute.key,
|
51
|
+
:default => attribute.default,
|
52
|
+
:serialize => attribute.serialize,
|
53
|
+
:if => attribute.if_cond,
|
54
|
+
:unless => attribute.unless_cond
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_optional_attrs(klass)
|
60
|
+
optional_attributes.each do |attribute|
|
61
|
+
klass.attr_optional attribute.name, {
|
62
|
+
:name => attribute.name,
|
63
|
+
:key => attribute.key,
|
64
|
+
:default => attribute.default,
|
65
|
+
:serialize => attribute.serialize
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
59
69
|
end
|
60
70
|
|
61
71
|
def attributes
|
data/lib/data_package/field.rb
CHANGED
data/lib/data_package/package.rb
CHANGED
@@ -6,7 +6,6 @@ module DataPackage
|
|
6
6
|
attr_optional :title
|
7
7
|
attr_optional :version
|
8
8
|
attr_optional :description
|
9
|
-
attr_optional :last_modified
|
10
9
|
attr_optional :datapackage_version
|
11
10
|
|
12
11
|
attr_optional :sources, :serialize => Proc.new { |source|
|
@@ -33,6 +32,13 @@ module DataPackage
|
|
33
32
|
|
34
33
|
def initialize(base_path, attrs = {})
|
35
34
|
@base_path = base_path
|
35
|
+
|
36
|
+
@resources ||= []
|
37
|
+
@sources ||= []
|
38
|
+
@licenses ||= []
|
39
|
+
@maintainters ||= []
|
40
|
+
@contributors ||= []
|
41
|
+
|
36
42
|
super(attrs)
|
37
43
|
end
|
38
44
|
|
@@ -43,6 +43,8 @@ module DataPackage
|
|
43
43
|
when :data
|
44
44
|
data.each(&block)
|
45
45
|
when :path
|
46
|
+
file_path = File.join(base_path, path)
|
47
|
+
|
46
48
|
case format
|
47
49
|
when 'csv'
|
48
50
|
DataKit::CSV::Parser.new(file_path).each_row(&block)
|
@@ -56,19 +58,6 @@ module DataPackage
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
def file_path
|
60
|
-
case data_source_type
|
61
|
-
when :data
|
62
|
-
nil # do something here
|
63
|
-
when :path
|
64
|
-
File.join(base_path, path) # do something here
|
65
|
-
when :url
|
66
|
-
raise "URL based resources are not yet supported"
|
67
|
-
else
|
68
|
-
raise "Resources require one of data, path or url keys to be specified"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
61
|
private
|
73
62
|
|
74
63
|
def data_source_type
|
data/lib/data_package/schema.rb
CHANGED
data/lib/data_package/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_package
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mode Analytics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rcsv
|