data_package 0.0.5 → 0.0.6

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: cdd1a91b8d504a0069e01f3289f4e374db9be84e
4
- data.tar.gz: d80447fed17c1ad21c7e9982ce0b94d15b1c4587
3
+ metadata.gz: c32d939169849aa526e542b913a074a24c0d3b5e
4
+ data.tar.gz: daf0cab3aa5f972ba928b38a0911c27ac09630fe
5
5
  SHA512:
6
- metadata.gz: b1de349cf66bb2550dbc193ea4ed1a82288ddb665da608a7c1a1fcfa22f4accc9a068fef268929a1a7d2f83f78fb4a61c0278b46fdfb840e0f879d9a0c23fba7
7
- data.tar.gz: 3f002d0d49864cd05cdc6cb14116f862665a91fb6d34621e5489f7f85cfdbc737a277acb306b4d3aa48562f15d1ca495384a27d3a786b15bcc3832fb797373f1
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
- serializable_attrs => [...]
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
- required_attributes.each do |attribute|
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
- optional_attributes.each do |attribute|
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
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module DataPackage
2
4
  class Field < Base
3
5
  Types = Set.new([
@@ -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
@@ -6,6 +6,12 @@ module DataPackage
6
6
 
7
7
  attr_optional :primary_key, :key => 'primaryKey'
8
8
 
9
+ def initialize(attrs = {})
10
+ @fields ||= []
11
+
12
+ super(attrs)
13
+ end
14
+
9
15
  def fields=(json)
10
16
  @fields = json.collect{|f| Field.new(f)}
11
17
  end
@@ -1,3 +1,3 @@
1
1
  module DataPackage
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -14,7 +14,7 @@ describe DataPackage::Package do
14
14
 
15
15
  package.name.should == 'mypackage'
16
16
  package.version.should == '0.0.1'
17
- package.resources.should == nil
17
+ package.resources.should == []
18
18
  package.base_path.should == tmpdir
19
19
  end
20
20
 
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.5
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: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rcsv