symbolmatrix 1.1.2 → 1.1.3

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.
@@ -0,0 +1,20 @@
1
+ Feature: Print to YAML
2
+ I want to be able to print a SymbolMatrix into YAML
3
+ with a simple Hash format
4
+
5
+ Scenario: A simple SymbolMatrix
6
+ Given the SymbolMatrix:
7
+ """
8
+ a:
9
+ simple: symbolmatrix
10
+ with: data
11
+ """
12
+ When I write it to YAML
13
+ Then I should have
14
+ """
15
+ ---
16
+ a:
17
+ simple: symbolmatrix
18
+ with: data
19
+
20
+ """
@@ -0,0 +1,7 @@
1
+ When /^I write it to YAML$/ do
2
+ @yaml = @symbolmatrix.to.yaml
3
+ end
4
+
5
+ Then /^I should have$/ do |yaml|
6
+ @yaml.should == yaml
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Symbolmatrix
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/lib/symbolmatrix.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'json'
2
3
  require 'discoverer'
3
4
 
4
5
  require 'symbolmatrix/symbolmatrix'
@@ -31,6 +31,26 @@ module Writer
31
31
  end
32
32
  the_hash
33
33
  end
34
+
35
+ def json
36
+ @source.to_json
37
+ end
38
+
39
+ def yaml
40
+ string_key_hash.to_yaml
41
+ end
42
+
43
+ def string_key_hash
44
+ the_hash = {}
45
+ @source.each do |key, value|
46
+ if value.respond_to? :to
47
+ the_hash[key.to_s] = value.to.string_key_hash
48
+ else
49
+ the_hash[key.to_s] = value
50
+ end
51
+ end
52
+ the_hash
53
+ end
34
54
  end
35
55
  end
36
56
 
@@ -38,7 +38,7 @@ describe Reader::SymbolMatrix do
38
38
  end
39
39
  end
40
40
 
41
- shared_examples_for "any serialization" do
41
+ shared_examples_for "any reader serialization" do
42
42
  it 'should call merge! to source with the parsed data' do
43
43
  the_sm = stub 'sm'
44
44
  data_stub = stub 'data'
@@ -52,12 +52,12 @@ describe Reader::SymbolMatrix do
52
52
 
53
53
  describe "#serialization" do
54
54
  before { @method = :serialization }
55
- it_behaves_like 'any serialization'
55
+ it_behaves_like 'any reader serialization'
56
56
  end
57
57
 
58
58
  describe '#smas' do
59
59
  before { @method = :smas }
60
- it_behaves_like 'any serialization'
60
+ it_behaves_like 'any reader serialization'
61
61
  end
62
62
  end
63
63
 
@@ -43,7 +43,7 @@ describe Writer::SymbolMatrix do
43
43
  end
44
44
  end
45
45
 
46
- shared_examples_for 'any serialization' do
46
+ shared_examples_for 'any writer serialization' do
47
47
  it 'should serialize "try: this" into "try:this"' do
48
48
  s = SymbolMatrix try: "this"
49
49
  writer = Writer::SymbolMatrix.new s
@@ -139,12 +139,37 @@ describe Writer::SymbolMatrix do
139
139
 
140
140
  describe '#serialization' do
141
141
  before { @method = :serialization }
142
- it_behaves_like 'any serialization'
142
+ it_behaves_like 'any writer serialization'
143
143
  end
144
144
 
145
145
  describe '#smas' do
146
146
  before { @method = :smas }
147
- it_behaves_like 'any serialization'
147
+ it_behaves_like 'any writer serialization'
148
+ end
149
+
150
+ describe '#json' do
151
+ it 'should return a json serialization' do
152
+ sm = SymbolMatrix alpha: { beta: "gamma" }
153
+ writer = Writer::SymbolMatrix.new sm
154
+ writer.json.should == '{"alpha":{"beta":"gamma"}}'
155
+ end
156
+ end
157
+
158
+ describe '#yaml' do
159
+ it 'should return a yaml serialization' do
160
+ sm = SymbolMatrix alpha: { beta: "gamma" }
161
+ writer = Writer::SymbolMatrix.new sm
162
+ writer.yaml.should include "alpha:\n beta: gamma"
163
+ end
164
+ end
165
+
166
+ describe '#string_key_hash' do
167
+ it 'should convert a SymbolMatrix to a multidimentional hash with all string keys' do
168
+ sm = SymbolMatrix alpha: { beta: "gamma" }
169
+ writer = Writer::SymbolMatrix.new sm
170
+ writer.string_key_hash
171
+ .should == { "alpha" => { "beta" => "gamma"} }
172
+ end
148
173
  end
149
174
  end
150
175
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbolmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: discoverer
@@ -75,8 +75,10 @@ files:
75
75
  - README.md
76
76
  - Rakefile
77
77
  - features/parse_serialization.feature
78
+ - features/print_to_yaml.feature
78
79
  - features/serialize.feature
79
80
  - features/stepdefs/parse_serialization.rb
81
+ - features/stepdefs/print_to_yaml.rb
80
82
  - features/stepdefs/serialize.rb
81
83
  - features/support/env.rb
82
84
  - lib/reader/symbolmatrix.rb
@@ -119,8 +121,10 @@ summary: Very useful for configuration files, SymbolMatrix is a hash-like multid
119
121
  Symbol-only class with ability to discover and load YAML data
120
122
  test_files:
121
123
  - features/parse_serialization.feature
124
+ - features/print_to_yaml.feature
122
125
  - features/serialize.feature
123
126
  - features/stepdefs/parse_serialization.rb
127
+ - features/stepdefs/print_to_yaml.rb
124
128
  - features/stepdefs/serialize.rb
125
129
  - features/support/env.rb
126
130
  - spec/complete_features_helper.rb