pragmatic_context 0.1.1 → 0.1.2

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: e2ec6ccfc5c04da2f9decfe359fde2b08a056d84
4
- data.tar.gz: 7497e0289cc5c38616f91ce6a2d6adcd8ee1eb31
3
+ metadata.gz: 172596b7b54c27b64dd8387556afab2ea83ed373
4
+ data.tar.gz: e55900a1261bdc44770b36325c73643dce742fd6
5
5
  SHA512:
6
- metadata.gz: 0bbe3d6badf4a09768da5ce2ae9d9cedf2e5c4a897904ef029535e980c1f9189bd9b7076578462998ec7994155097de7266fa02dcb3512e724733f481595e441
7
- data.tar.gz: d4c27b700f9f4c88e3a66e6cd830dc878fdf4f61a9e103e8dac65905685f54d4bb211c7f1b0c9c61ba8eb87ce09132acecae3d93f753af17bf329e7c8bdf2470
6
+ metadata.gz: 1933a9be02c54a3a9057aa253c8f3b2171b83a370b24d43245483b08097d87dadc51a9995bb07952e60ade4889b29f8fb9188a0b7e2793c325774e2bfe3b2692
7
+ data.tar.gz: 6081281c6c0cddaefc9f64f0ba317eb0a8c750c90c47fc0ac0f41933a4200fe45b4df02656accb3833b184c046fcf49e26362fcfa9e9d05078eb75d69f985a57
@@ -41,6 +41,14 @@ module PragmaticContext
41
41
  value = self.send(term)
42
42
  if (value.is_a? Contextualizable)
43
43
  results[term] = self.send(term).as_jsonld
44
+ elsif (value.is_a? Array)
45
+ results[term] = self.send(term).each_with_index.map do |element, idx|
46
+ if (element.is_a? Contextualizable)
47
+ element.as_jsonld
48
+ else
49
+ json_results[term][idx]
50
+ end
51
+ end
44
52
  elsif (value.is_a? Hash)
45
53
  self.send(term).each do |key, value|
46
54
  results["#{term}:#{key}"] = value
@@ -1,3 +1,3 @@
1
1
  module PragmaticContext
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -86,6 +86,47 @@ describe PragmaticContext::Contextualizable do
86
86
  }
87
87
  end
88
88
 
89
+ it 'should properly render literals within lists' do
90
+ @contextualizer.stub(:definitions_for_terms) do |terms|
91
+ { 'bacon' => { "@id" => "http://bacon.yum" },
92
+ 'ham' => { "@id" => "http://ham.yum" } }.slice(*terms)
93
+ end
94
+ subject.bacon = ['crispy', 'back', 'peameal']
95
+ subject.ham = ['honey', 'black forest', 'spiral']
96
+ subject.as_jsonld.should == {
97
+ "@context" => subject.jsonld_context,
98
+ "bacon" => ['crispy', 'back', 'peameal'],
99
+ "ham" => ['honey', 'black forest', 'spiral']
100
+ }
101
+ end
102
+
103
+ it 'should recurse into Contextualizable subobjects within lists' do
104
+ @contextualizer.stub(:definitions_for_terms) do |terms|
105
+ { 'bacon' => { "@id" => "http://bacon.yum" },
106
+ 'ham' => { "@id" => "http://ham.yum" } }.slice(*terms)
107
+ end
108
+ subject.bacon = [Stub.new]
109
+ subject.ham = [Stub.new, 'honey', Stub.new]
110
+ subject.bacon[0].bacon = 'nested bacon'
111
+ subject.ham[0].ham = 'nested ham'
112
+ subject.ham[2].ham = 'nested ham 2'
113
+ subject.as_jsonld.should == {
114
+ "@context" => subject.jsonld_context,
115
+ "bacon" => [{ "@context" => subject.bacon[0].jsonld_context,
116
+ "bacon" => "nested bacon",
117
+ "ham" => nil
118
+ }],
119
+ "ham" => [{ "@context" => subject.ham[0].jsonld_context,
120
+ "bacon" => nil,
121
+ "ham" => "nested ham"},
122
+ 'honey',
123
+ { "@context" => subject.ham[2].jsonld_context,
124
+ "bacon" => nil,
125
+ "ham" => "nested ham 2"
126
+ }]
127
+ }
128
+ end
129
+
89
130
  it 'should compact sub-hashes into namespaced properties on self' do
90
131
  @contextualizer.stub(:definitions_for_terms) do |terms|
91
132
  { 'bacon' => { "@id" => "http://bacon.yum" },
@@ -121,4 +162,3 @@ describe PragmaticContext::Contextualizable do
121
162
  end
122
163
  end
123
164
  end
124
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragmatic_context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Trudel