empezar 0.1.3 → 0.2.0
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.
- data/lib/empezar/version.rb +1 -1
- data/lib/empezar.rb +3 -1
- data/lib/writer/symbolmatrix.rb +21 -0
- data/spec/writer/symbolmatrix_spec.rb +36 -0
- metadata +4 -1
data/lib/empezar/version.rb
CHANGED
data/lib/empezar.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Writer
|
2
|
+
class SymbolMatrix
|
3
|
+
attr_accessor :source
|
4
|
+
|
5
|
+
def initialize source
|
6
|
+
@source = source
|
7
|
+
end
|
8
|
+
|
9
|
+
def serialization prefix = ""
|
10
|
+
text = ""
|
11
|
+
@source.each do |key, value|
|
12
|
+
if value.is_a? Hash
|
13
|
+
text += value.to.serialization(prefix + key.to_s + ".") +" "
|
14
|
+
else
|
15
|
+
text += "#{prefix}#{key}:#{value} "
|
16
|
+
end
|
17
|
+
end
|
18
|
+
text[0..-2]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Writer::SymbolMatrix do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should set the argument as the source' do
|
6
|
+
source = stub 'source'
|
7
|
+
writer = Writer::SymbolMatrix.new source
|
8
|
+
writer.source.should == source
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#serialization' do
|
13
|
+
it 'should transform the multidimentional hash into a simple dot and colons serialization' do
|
14
|
+
multidimentional = SymbolMatrix.new hola: {
|
15
|
+
the: "start",
|
16
|
+
asdfdf: 8989,
|
17
|
+
of: {
|
18
|
+
some: "multidimentional"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
stuff: "oops"
|
22
|
+
|
23
|
+
writer = Writer::SymbolMatrix.new multidimentional
|
24
|
+
writer.serialization.should == "hola.the:start hola.asdfdf:8989 hola.of.some:multidimentional stuff:oops"
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with argument' do
|
28
|
+
it 'should do the transformation appending the argument to each key-value pair' do
|
29
|
+
simple = SymbolMatrix.new mykey: "myvalue", otherkey: "othervalue"
|
30
|
+
|
31
|
+
writer = Writer::SymbolMatrix.new simple
|
32
|
+
writer.serialization("inside.").should == "inside.mykey:myvalue inside.otherkey:othervalue"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: empezar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/empezar/runner.rb
|
98
98
|
- lib/empezar/symbolmatrix.rb
|
99
99
|
- lib/empezar/version.rb
|
100
|
+
- lib/writer/symbolmatrix.rb
|
100
101
|
- sample/config/main.yaml
|
101
102
|
- sample/script.rb
|
102
103
|
- spec/configuration_spec.rb
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- spec/runner_spec.rb
|
109
110
|
- spec/spec_helper.rb
|
110
111
|
- spec/symbolmatrix_spec.rb
|
112
|
+
- spec/writer/symbolmatrix_spec.rb
|
111
113
|
homepage: http://github.com/Fetcher/empezar
|
112
114
|
licenses: []
|
113
115
|
post_install_message:
|
@@ -143,4 +145,5 @@ test_files:
|
|
143
145
|
- spec/runner_spec.rb
|
144
146
|
- spec/spec_helper.rb
|
145
147
|
- spec/symbolmatrix_spec.rb
|
148
|
+
- spec/writer/symbolmatrix_spec.rb
|
146
149
|
has_rdoc:
|