fedora_lens 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fedora_lens/lenses.rb +14 -1
- data/lib/fedora_lens/version.rb +1 -1
- data/spec/fedora_lens/lenses_spec.rb +39 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4327c804e83a80178cf702ee3a33c69aaf598b3c
|
4
|
+
data.tar.gz: fe2f5b45ec70975ddd452803f998f44c0600d5c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed807150e20a30089687a089fade449c9366ac7fdb4b81adff2a9f70dc9eae16a68e066f56e3e945ed22aeda5b8af96ed2feb3507e12f7f07e4972c25e5b6506
|
7
|
+
data.tar.gz: fc63d6caab8880c71921e7d3e276f0faa16c59006edfe08cbf1a24d39307d7dc66da939efcfd8176a92de6925f71ccc4b7663ad5aa3c9c9ffa81f6456abbe471
|
data/lib/fedora_lens/lenses.rb
CHANGED
@@ -34,6 +34,19 @@ module FedoraLens
|
|
34
34
|
]
|
35
35
|
end
|
36
36
|
|
37
|
+
def literals_to_strings
|
38
|
+
Lens[
|
39
|
+
get: lambda do |source|
|
40
|
+
source.map(&:to_s)
|
41
|
+
end,
|
42
|
+
put: lambda do |sources, values|
|
43
|
+
Array(values).map do |value|
|
44
|
+
RDF::Literal.new(value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
37
50
|
def hash_update
|
38
51
|
Lens[
|
39
52
|
get: lambda {|hash| hash[key]},
|
@@ -84,7 +97,7 @@ module FedoraLens
|
|
84
97
|
end,
|
85
98
|
put: lambda do |orm, values|
|
86
99
|
orm.graph.delete([orm.resource.subject_uri, predicate, nil])
|
87
|
-
(values
|
100
|
+
Array(values).each do |value|
|
88
101
|
orm.graph.insert([orm.resource.subject_uri, predicate, value])
|
89
102
|
end
|
90
103
|
orm
|
data/lib/fedora_lens/version.rb
CHANGED
@@ -20,6 +20,42 @@ module FedoraLens
|
|
20
20
|
test_lens Lenses.single, [:one, :two], :foo
|
21
21
|
end
|
22
22
|
|
23
|
+
describe ".literals_to_strings" do
|
24
|
+
let(:lens) { Lenses.literals_to_strings }
|
25
|
+
|
26
|
+
subject { lens.get(input) }
|
27
|
+
|
28
|
+
describe "#get" do
|
29
|
+
let(:input) { [RDF::Literal.new('foo'), RDF::Literal.new('bar')] }
|
30
|
+
it "casts them to string" do
|
31
|
+
expect(subject).to eq ['foo', 'bar']
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with an empty result" do
|
35
|
+
let(:input) { [] }
|
36
|
+
it "casts them to string" do
|
37
|
+
expect(subject).to eq []
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#put" do
|
43
|
+
subject { lens.put([RDF::Literal.new("foo"), RDF::Literal.new("bar")], input) }
|
44
|
+
let(:input) { ['quack', 'quix'] }
|
45
|
+
it "overwrites the items" do
|
46
|
+
expect(subject).to eq [RDF::Literal.new("quack"), RDF::Literal.new("quix")]
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with an empty set" do
|
50
|
+
let(:input) { nil }
|
51
|
+
it "casts them to string" do
|
52
|
+
expect(subject).to eq []
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
23
59
|
describe ".as_dom" do
|
24
60
|
it "converts xml to a Nokogiri::XML::Document" do
|
25
61
|
xml = "<foo><bar>content</bar></foo>"
|
@@ -65,6 +101,9 @@ module FedoraLens
|
|
65
101
|
it "converts an Ldp::Orm to the value of the specified predicate" do
|
66
102
|
Lenses.get_predicate(RDF::DC11.title).get(orm).first.should eq RDF::Literal.new("title")
|
67
103
|
end
|
104
|
+
it "gets an empty set" do
|
105
|
+
Lenses.get_predicate(RDF::DC11.description).get(orm).should eq []
|
106
|
+
end
|
68
107
|
it "sets the value of an Ldp::Orm for the specified predicate" do
|
69
108
|
Lenses.get_predicate(RDF::DC11.title).put(orm, [RDF::Literal.new("new")]).value(RDF::DC11.title).first.should eq RDF::Literal.new("new")
|
70
109
|
end
|