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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7eaf60a6e220490635c6c9eef2c99cbe7453eaf
4
- data.tar.gz: a0e300edb02fbd2abfdeee0c5368e43df86a35e1
3
+ metadata.gz: 4327c804e83a80178cf702ee3a33c69aaf598b3c
4
+ data.tar.gz: fe2f5b45ec70975ddd452803f998f44c0600d5c0
5
5
  SHA512:
6
- metadata.gz: 4bd613f55ea525abba224a54ad39df2fcb0e8779bdbd4f95238c81e3c5b74dde7aeffb771e56b1d0bfdacdd2b3ce902db62747854b8cc4dfc682977f5eab7d06
7
- data.tar.gz: 75a8cf0ac3f5d4ce1f7f26d3877e1cb64cc5d7bdd419458156cb84177d1ae2601cb6dbc6c3a40f9bb7fc2c2ff6029c126e81fcb39d077c5a643bb32fd93725b0
6
+ metadata.gz: ed807150e20a30089687a089fade449c9366ac7fdb4b81adff2a9f70dc9eae16a68e066f56e3e945ed22aeda5b8af96ed2feb3507e12f7f07e4972c25e5b6506
7
+ data.tar.gz: fc63d6caab8880c71921e7d3e276f0faa16c59006edfe08cbf1a24d39307d7dc66da939efcfd8176a92de6925f71ccc4b7663ad5aa3c9c9ffa81f6456abbe471
@@ -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 || []).each do |value|
100
+ Array(values).each do |value|
88
101
  orm.graph.insert([orm.resource.subject_uri, predicate, value])
89
102
  end
90
103
  orm
@@ -1,3 +1,3 @@
1
1
  module FedoraLens
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedora_lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne