dbd 0.0.6 → 0.0.7

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: cc144cf2ae12eb90508d2da68006a9cc5ac247dd
4
- data.tar.gz: 7bac3b578951f4a3a610aa988d5f06c180095368
3
+ metadata.gz: 34e70c3c3d08093acee3610c0e3d93ac5bace6b6
4
+ data.tar.gz: 64f2171e686baaa681c3dccef02ef7feb543b71b
5
5
  SHA512:
6
- metadata.gz: 0e0f6fa90ad08943e62780b350a058e4d27286eb0396e3524222cd4d488ca81ac3764b58076bdb5331a91cd851fa710440a3e1b7060e81d2734c2f069f56a8ed
7
- data.tar.gz: fb95d9bb0d1ecb5f13d297fa69ab01d661e460653d80333967583c46e843412ea46324fa025330d59f1dfcbf19c4dd5fa53a51099fe39db9d972a0e5339b1595
6
+ metadata.gz: 202ce2b19b1c53a04aa84c0089935baf715f76ed0836d0aaf2259ea930f528592e71ad45f6580679dd1fb5d3174755cbe943092f6c2ac275016294b5908e1920
7
+ data.tar.gz: 64dd10c180cb960f408d3de9be9227c392a2dddc93a6db8c4e0e1baa11345b6591df0a3a227fe3ca79d57366c6cfd584378cddabb1b5a327e0c1baf22955b90a
data/HISTORY.txt CHANGED
@@ -32,3 +32,8 @@
32
32
  =====
33
33
 
34
34
  * Fact.from_CSV reads from a CSV stream (file or stringIO)
35
+
36
+ 0.0.7 (18 June 2013)
37
+ =====
38
+
39
+ * fix a bug in TimeStamp round trip in JRuby
data/README.md CHANGED
@@ -48,65 +48,74 @@ Open Source [MIT]
48
48
 
49
49
  ## Examples
50
50
 
51
- Also see the file `docs/test.rb`.
51
+ Also see the file `docs/test.rb` to execute the script below.
52
52
 
53
53
  ```
54
54
  require 'dbd'
55
55
 
56
56
  provenance = Dbd::ProvenanceResource.new
57
57
 
58
- fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
59
- fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
60
- fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
61
- fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
62
- fact_license_MIT = Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
63
- provenance << fact_context_public
64
- provenance << fact_source_dbd
65
- provenance << fact_creator_peter_v
66
- provenance << fact_created_now
67
- provenance << fact_license_MIT
58
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
59
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
60
+ provenance << Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
61
+ provenance << Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
62
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
68
63
 
69
64
  nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
70
65
 
71
- fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
72
- fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
73
- fact_EU_comment = Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
74
- fact_EU_story = Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
75
- nobel_peace_2012 << fact_nobel_peace_2012
76
- nobel_peace_2012 << fact_EU_label
77
- nobel_peace_2012 << fact_EU_comment
78
- nobel_peace_2012 << fact_EU_story
66
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
67
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
68
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
69
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
79
70
 
80
71
  graph = Dbd::Graph.new
81
72
 
82
- graph << [provenance, nobel_peace_2012]
73
+ graph << provenance << nobel_peace_2012
83
74
 
84
75
  puts "facts in short representation:"
85
76
  puts graph.map(&:short)
77
+
86
78
  # facts in short representation:
87
- # [ prov ] : 78b0d99b : prov:context : public
88
- # [ prov ] : 78b0d99b : prov:source : http://github.com/petervandenabeele/dbd
89
- # [ prov ] : 78b0d99b : dcterms:creator : @peter_v
90
- # [ prov ] : 78b0d99b : dcterms:created : 2013-05-29 22:10:14 UTC
91
- # [ prov ] : 78b0d99b : prov:license : MIT
92
- # 78b0d99b : 0db0caee : todo:nobelPeacePriceWinn : 2012
93
- # 78b0d99b : 0db0caee : rdfs:label : EU
94
- # 78b0d99b : 0db0caee : rdfs:comment : European Union
95
- # 78b0d99b : 0db0caee : todo:story : A long period of peace,_ that is a "bliss".
79
+ # [ prov ] : 5eb1ea27 : prov:context : public
80
+ # [ prov ] : 5eb1ea27 : prov:source : http://github.com/petervandenabeele/dbd
81
+ # [ prov ] : 5eb1ea27 : dcterms:creator : @peter_v
82
+ # [ prov ] : 5eb1ea27 : dcterms:created : 2013-06-19 22:02:20 UTC
83
+ # [ prov ] : 5eb1ea27 : prov:license : MIT
84
+ # 5eb1ea27 : 3767c493 : todo:nobelPeacePriceWinn : 2012
85
+ # 5eb1ea27 : 3767c493 : rdfs:label : EU
86
+ # 5eb1ea27 : 3767c493 : rdfs:comment : European Union
87
+ # 5eb1ea27 : 3767c493 : todo:story : A long period of peace,_ that is a "bliss".
88
+
89
+ csv = graph.to_CSV
96
90
 
97
91
  puts "facts in full detail in CSV:"
98
- puts graph.to_CSV
92
+ puts csv
93
+
99
94
  # facts in full detail in CSV:
100
- # "58c33e41-87c7-4403-b058-60e4ebf063ed","2013-05-29 22:10:14.811038737 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:context","public"
101
- # "44f72707-f0af-4e1e-8674-8009aedda826","2013-05-29 22:10:14.811075014 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:source","http://github.com/petervandenabeele/dbd"
102
- # "dd409d99-cdb5-4a99-a3c1-cfb64b1eaa62","2013-05-29 22:10:14.811092335 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:creator","@peter_v"
103
- # "a135916e-b055-4da5-805f-6adba927c935","2013-05-29 22:10:14.811105102 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:created","2013-05-29 22:10:14 UTC"
104
- # "345d455d-3f2d-4b9e-9084-d866c767feba","2013-05-29 22:10:14.811116493 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:license","MIT"
105
- # "1d49db69-9b7a-49b7-be87-7ca7e88a20f6","2013-05-29 22:10:14.811135641 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:nobelPeacePriceWinner","2012"
106
- # "ce620335-a661-4a72-a932-1fe904f3db8a","2013-05-29 22:10:14.811151313 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:label","EU"
107
- # "a694f74b-219d-4e23-936a-5f10b77fe321","2013-05-29 22:10:14.811164540 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:comment","European Union"
108
- # "85732e38-79d9-48d0-8611-0bed25883bd3","2013-05-29 22:10:14.811176113 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:story","A long period of peace,
109
- # that is a ""bliss""."
95
+ # "4720034a-01ea-4b6b-b9aa-45cb8c7c5e64","2013-06-19 22:02:20.489834224 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:context","public"
96
+ # "d05a0a6c-a003-4320-b52b-a6e49e854437","2013-06-19 22:02:20.489889896 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:source","http://github.com/petervandenabeele/dbd"
97
+ # "fc47abbd-da2d-4562-bb6b-ed8b84005734","2013-06-19 22:02:20.489913758 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","dcterms:creator","@peter_v"
98
+ # "f240e975-5d39-41eb-bb5a-cc59ede4c1a6","2013-06-19 22:02:20.489932320 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","dcterms:created","2013-06-19 22:02:20 UTC"
99
+ # "d592b1e8-2910-4329-b502-7d960cebb399","2013-06-19 22:02:20.489950713 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:license","MIT"
100
+ # "a2d55e46-03f2-470e-8347-c36b31e7facc","2013-06-19 22:02:20.489973271 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","todo:nobelPeacePriceWinner","2012"
101
+ # "0766dd24-70e5-487d-a018-d58da75dcdad","2013-06-19 22:02:20.489996422 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","rdfs:label","EU"
102
+ # "eda61baa-b331-462e-b7b5-5d6eb2e9a053","2013-06-19 22:02:20.490014676 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","rdfs:comment","European Union"
103
+ # "a3da9295-b43a-4c3a-8e8c-97c3f04c1fa3","2013-06-19 22:02:20.490036790 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","todo:story","A long period of peace,
104
+ # that is a ""bliss""."
105
+
106
+ imported_graph = Dbd::Graph.from_CSV(csv)
107
+
108
+ puts imported_graph.map(&:short)
109
+
110
+ # [ prov ] : 5eb1ea27 : prov:context : public
111
+ # [ prov ] : 5eb1ea27 : prov:source : http://github.com/petervandenabeele/dbd
112
+ # [ prov ] : 5eb1ea27 : dcterms:creator : @peter_v
113
+ # [ prov ] : 5eb1ea27 : dcterms:created : 2013-06-19 22:02:20 UTC
114
+ # [ prov ] : 5eb1ea27 : prov:license : MIT
115
+ # 5eb1ea27 : 3767c493 : todo:nobelPeacePriceWinn : 2012
116
+ # 5eb1ea27 : 3767c493 : rdfs:label : EU
117
+ # 5eb1ea27 : 3767c493 : rdfs:comment : European Union
118
+ # 5eb1ea27 : 3767c493 : todo:story : A long period of peace,_ that is a "bliss".
110
119
  ```
111
120
 
112
121
  [RDF]: http://www.w3.org/RDF/
data/dbd.gemspec CHANGED
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'yard'
27
27
  spec.add_runtime_dependency 'neography'
28
28
  spec.add_runtime_dependency 'rdf', '~> 1.0.6'
29
- spec.add_runtime_dependency 'ruby_peter_v', '>= 0.0.9'
29
+ spec.add_runtime_dependency 'ruby_peter_v', '>= 0.0.8'
30
30
  end
data/docs/test.rb CHANGED
@@ -2,55 +2,64 @@ require 'dbd'
2
2
 
3
3
  provenance = Dbd::ProvenanceResource.new
4
4
 
5
- fact_context_public = Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
6
- fact_source_dbd = Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
7
- fact_creator_peter_v = Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
8
- fact_created_now = Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
9
- fact_license_MIT = Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
10
- provenance << fact_context_public
11
- provenance << fact_source_dbd
12
- provenance << fact_creator_peter_v
13
- provenance << fact_created_now
14
- provenance << fact_license_MIT
5
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:context", object: "public")
6
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:source", object: "http://github.com/petervandenabeele/dbd")
7
+ provenance << Dbd::ProvenanceFact.new(predicate: "dcterms:creator", object: "@peter_v")
8
+ provenance << Dbd::ProvenanceFact.new(predicate: "dcterms:created", object: Time.now.utc)
9
+ provenance << Dbd::ProvenanceFact.new(predicate: "prov:license", object: "MIT")
15
10
 
16
11
  nobel_peace_2012 = Dbd::Resource.new(provenance_subject: provenance.subject)
17
12
 
18
- fact_nobel_peace_2012 = Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
19
- fact_EU_label = Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
20
- fact_EU_comment = Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
21
- fact_EU_story = Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
22
- nobel_peace_2012 << fact_nobel_peace_2012
23
- nobel_peace_2012 << fact_EU_label
24
- nobel_peace_2012 << fact_EU_comment
25
- nobel_peace_2012 << fact_EU_story
13
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:nobelPeacePriceWinner", object: "2012")
14
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:label", object: "EU") # this will use some RDF predicates in future
15
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "rdfs:comment", object: "European Union")
16
+ nobel_peace_2012 << Dbd::Fact.new(predicate: "todo:story", object: "A long period of peace,\n that is a \"bliss\".")
26
17
 
27
18
  graph = Dbd::Graph.new
28
19
 
29
- graph << [provenance, nobel_peace_2012]
20
+ graph << provenance << nobel_peace_2012
30
21
 
31
22
  puts "facts in short representation:"
32
23
  puts graph.map(&:short)
24
+
33
25
  # facts in short representation:
34
- # [ prov ] : 78b0d99b : prov:context : public
35
- # [ prov ] : 78b0d99b : prov:source : http://github.com/petervandenabeele/dbd
36
- # [ prov ] : 78b0d99b : dcterms:creator : @peter_v
37
- # [ prov ] : 78b0d99b : dcterms:created : 2013-05-29 22:10:14 UTC
38
- # [ prov ] : 78b0d99b : prov:license : MIT
39
- # 78b0d99b : 0db0caee : todo:nobelPeacePriceWinn : 2012
40
- # 78b0d99b : 0db0caee : rdfs:label : EU
41
- # 78b0d99b : 0db0caee : rdfs:comment : European Union
42
- # 78b0d99b : 0db0caee : todo:story : A long period of peace,_ that is a "bliss".
26
+ # [ prov ] : 5eb1ea27 : prov:context : public
27
+ # [ prov ] : 5eb1ea27 : prov:source : http://github.com/petervandenabeele/dbd
28
+ # [ prov ] : 5eb1ea27 : dcterms:creator : @peter_v
29
+ # [ prov ] : 5eb1ea27 : dcterms:created : 2013-06-19 22:02:20 UTC
30
+ # [ prov ] : 5eb1ea27 : prov:license : MIT
31
+ # 5eb1ea27 : 3767c493 : todo:nobelPeacePriceWinn : 2012
32
+ # 5eb1ea27 : 3767c493 : rdfs:label : EU
33
+ # 5eb1ea27 : 3767c493 : rdfs:comment : European Union
34
+ # 5eb1ea27 : 3767c493 : todo:story : A long period of peace,_ that is a "bliss".
35
+
36
+ csv = graph.to_CSV
43
37
 
44
38
  puts "facts in full detail in CSV:"
45
- puts graph.to_CSV
39
+ puts csv
40
+
46
41
  # facts in full detail in CSV:
47
- # "58c33e41-87c7-4403-b058-60e4ebf063ed","2013-05-29 22:10:14.811038737 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:context","public"
48
- # "44f72707-f0af-4e1e-8674-8009aedda826","2013-05-29 22:10:14.811075014 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:source","http://github.com/petervandenabeele/dbd"
49
- # "dd409d99-cdb5-4a99-a3c1-cfb64b1eaa62","2013-05-29 22:10:14.811092335 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:creator","@peter_v"
50
- # "a135916e-b055-4da5-805f-6adba927c935","2013-05-29 22:10:14.811105102 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","dcterms:created","2013-05-29 22:10:14 UTC"
51
- # "345d455d-3f2d-4b9e-9084-d866c767feba","2013-05-29 22:10:14.811116493 UTC","","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","prov:license","MIT"
52
- # "1d49db69-9b7a-49b7-be87-7ca7e88a20f6","2013-05-29 22:10:14.811135641 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:nobelPeacePriceWinner","2012"
53
- # "ce620335-a661-4a72-a932-1fe904f3db8a","2013-05-29 22:10:14.811151313 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:label","EU"
54
- # "a694f74b-219d-4e23-936a-5f10b77fe321","2013-05-29 22:10:14.811164540 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","rdfs:comment","European Union"
55
- # "85732e38-79d9-48d0-8611-0bed25883bd3","2013-05-29 22:10:14.811176113 UTC","78b0d99b-aaf9-4b67-9b84-43c3b7d44729","0db0caee-cc05-4f02-b90e-1ad4e72050a5","todo:story","A long period of peace,
56
- # that is a ""bliss""."
42
+ # "4720034a-01ea-4b6b-b9aa-45cb8c7c5e64","2013-06-19 22:02:20.489834224 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:context","public"
43
+ # "d05a0a6c-a003-4320-b52b-a6e49e854437","2013-06-19 22:02:20.489889896 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:source","http://github.com/petervandenabeele/dbd"
44
+ # "fc47abbd-da2d-4562-bb6b-ed8b84005734","2013-06-19 22:02:20.489913758 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","dcterms:creator","@peter_v"
45
+ # "f240e975-5d39-41eb-bb5a-cc59ede4c1a6","2013-06-19 22:02:20.489932320 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","dcterms:created","2013-06-19 22:02:20 UTC"
46
+ # "d592b1e8-2910-4329-b502-7d960cebb399","2013-06-19 22:02:20.489950713 UTC","","5eb1ea27-6691-4a57-ab13-8a59021968e1","prov:license","MIT"
47
+ # "a2d55e46-03f2-470e-8347-c36b31e7facc","2013-06-19 22:02:20.489973271 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","todo:nobelPeacePriceWinner","2012"
48
+ # "0766dd24-70e5-487d-a018-d58da75dcdad","2013-06-19 22:02:20.489996422 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","rdfs:label","EU"
49
+ # "eda61baa-b331-462e-b7b5-5d6eb2e9a053","2013-06-19 22:02:20.490014676 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","rdfs:comment","European Union"
50
+ # "a3da9295-b43a-4c3a-8e8c-97c3f04c1fa3","2013-06-19 22:02:20.490036790 UTC","5eb1ea27-6691-4a57-ab13-8a59021968e1","3767c493-79d3-4a97-a832-79e6361ddc4c","todo:story","A long period of peace,
51
+ # that is a ""bliss""."
52
+
53
+ imported_graph = Dbd::Graph.from_CSV(csv)
54
+
55
+ puts imported_graph.map(&:short)
56
+
57
+ # [ prov ] : 5eb1ea27 : prov:context : public
58
+ # [ prov ] : 5eb1ea27 : prov:source : http://github.com/petervandenabeele/dbd
59
+ # [ prov ] : 5eb1ea27 : dcterms:creator : @peter_v
60
+ # [ prov ] : 5eb1ea27 : dcterms:created : 2013-06-19 22:02:20 UTC
61
+ # [ prov ] : 5eb1ea27 : prov:license : MIT
62
+ # 5eb1ea27 : 3767c493 : todo:nobelPeacePriceWinn : 2012
63
+ # 5eb1ea27 : 3767c493 : rdfs:label : EU
64
+ # 5eb1ea27 : 3767c493 : rdfs:comment : European Union
65
+ # 5eb1ea27 : 3767c493 : todo:story : A long period of peace,_ that is a "bliss".
data/lib/dbd/fact.rb CHANGED
@@ -143,13 +143,14 @@ module Dbd
143
143
  end
144
144
 
145
145
  ##
146
- # Constructs a Fact from a values array
146
+ # Constructs a Fact or ProvenanceFact from a values array
147
147
  # (e.g. pulled from a CSV row).
148
148
  #
149
149
  # @param [Array] values Required : the array with values, organized as in attributes
150
- # @return [Fact] the constructed fact
150
+ # @return [Fact, ProvenanceFact] the constructed fact
151
151
  def self.from_values(values)
152
- new(Hash[[self.attributes, values].transpose])
152
+ hash = hash_from_values(values)
153
+ fact_from_hash(hash)
153
154
  end
154
155
 
155
156
  ##
@@ -204,7 +205,7 @@ module Dbd
204
205
  end
205
206
 
206
207
  ##
207
- # Confirms this is not a ProvenanceFact
208
+ # Confirms this is not a ProvenanceFact.
208
209
  #
209
210
  # Needed for validations that depend on different behavior for
210
211
  # a provenance_fact (mainly, no provenance_subject).
@@ -218,5 +219,19 @@ module Dbd
218
219
  "#{provenance_subject.to_s[0...8]}"
219
220
  end
220
221
 
222
+ def self.hash_from_values(values)
223
+ # Do not keep "empty" values (e.g. the provenance_subject for a ProvenanceFact).
224
+ attributes_values_array = [attributes, values].transpose.select{|a,v| v != ''}
225
+ Hash[attributes_values_array]
226
+ end
227
+
228
+ def self.fact_from_hash(hash)
229
+ if hash[:provenance_subject]
230
+ new(hash)
231
+ else
232
+ ProvenanceFact.new(hash)
233
+ end
234
+ end
235
+
221
236
  end
222
237
  end
data/lib/dbd/graph.rb CHANGED
@@ -45,7 +45,7 @@ module Dbd
45
45
  # @param [String] csv a string that contains the CSV serialization
46
46
  # @return [Graph] the imported graph
47
47
  def self.from_CSV(csv)
48
- Graph.new.tap do |graph|
48
+ new.tap do |graph|
49
49
  CSV.new(csv).each do |row|
50
50
  # TODO validate the input formats (e.g. invalid uuid codes)
51
51
  graph << Fact.from_values(row)
@@ -81,8 +81,19 @@ module Dbd
81
81
  ##
82
82
  # with a nanosecond granularity and in UTC
83
83
  def self.from_s(time_string)
84
- date_time = DateTime.strptime(time_string, time_format)
85
- TimeStamp.new(time: date_time.to_time.utc)
84
+ # For ns precision in JRuby this extended process is required
85
+ time_hash = DateTime._strptime(time_string, time_format)
86
+ raise(
87
+ ArgumentError,
88
+ "Time zone must be UTC, was #{time_hash[:zone]}") unless time_hash[:zone] == "UTC"
89
+ time = Time.utc(time_hash[:year],
90
+ time_hash[:mon],
91
+ time_hash[:mday],
92
+ time_hash[:hour],
93
+ time_hash[:min],
94
+ time_hash[:sec],
95
+ time_hash[:sec_fraction] * 1_000_000)
96
+ TimeStamp.new(time: time)
86
97
  end
87
98
 
88
99
  def >(other)
data/lib/dbd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dbd
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -3,26 +3,46 @@ require 'spec_helper'
3
3
  module Dbd
4
4
  describe Graph do
5
5
 
6
- def new_subject
7
- Fact.new_subject
6
+ def round_tripped_graph(graph)
7
+ Graph.from_CSV(StringIO.new(graph.to_CSV))
8
8
  end
9
9
 
10
10
  def validate_round_trip(graph)
11
- graph_from_csv = Graph.from_CSV(StringIO.new(graph.to_CSV))
12
-
13
- # use to_csv as the "identity function" for Graph
14
- graph.to_CSV.should == graph_from_csv.to_CSV
11
+ graph_from_CSV = round_tripped_graph(graph)
12
+ # temporarily use to_csv as the "identity function" for Graph
13
+ # TODO define a proper Equality for Graph and Fact
14
+ graph_from_CSV.to_CSV.should == graph.to_CSV
15
15
  end
16
16
 
17
17
  describe "#from_CSV reads back a csv exported graph correctly" do
18
- it "is correct for a graph with only provenance_facts" do
19
- graph = Factories::Graph.only_provenance
20
- validate_round_trip(graph)
18
+
19
+ describe "for a graph with only provenance_facts" do
20
+
21
+ let(:graph) { Factories::Graph.only_provenance }
22
+
23
+ it "round_trip validates" do
24
+ validate_round_trip(graph)
25
+ end
26
+
27
+ it "for a provenance_fact, the provenance_subject must be equal (nil)" do
28
+ graph_from_CSV = round_tripped_graph(graph)
29
+ provenance_fact = graph_from_CSV.first
30
+ provenance_fact.provenance_subject.should be_nil
31
+ end
21
32
  end
22
33
 
23
- it "is correct for a graph with facts and provenance_facts" do
24
- graph = Factories::Graph.only_provenance
25
- validate_round_trip(graph)
34
+ describe "for a graph with facts and provenance_facts" do
35
+
36
+ let(:graph) { Factories::Graph.full }
37
+
38
+ it "round_trip validates" do
39
+ validate_round_trip(graph)
40
+ end
41
+
42
+ it "the short export of a graph is correct after a round trip" do
43
+ imported_graph = Dbd::Graph.from_CSV(graph.to_CSV)
44
+ imported_graph.map(&:short).should == (graph.map(&:short))
45
+ end
26
46
  end
27
47
  end
28
48
  end
@@ -32,6 +32,11 @@ module Dbd
32
32
  time_stamp = described_class.from_s(a_time_stamp)
33
33
  time_stamp.to_s.should == a_time_stamp
34
34
  end
35
+
36
+ it "raises ArgumentError is time_zone is not UTC" do
37
+ time_CET = a_time_stamp.sub(/UTC/, 'CET')
38
+ lambda{ described_class.from_s(time_CET) }.should raise_error ArgumentError
39
+ end
35
40
  end
36
41
  end
37
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Vandenabeele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2013-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '>='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.0.9
131
+ version: 0.0.8
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.0.9
138
+ version: 0.0.8
139
139
  description: A data store that (almost) never forgets
140
140
  email:
141
141
  - peter@vandenabeele.com