sum_sum 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,12 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/sum_sum/compare/v0.0.2...master)
3
+ [full changelog](http://github.com/yolk/sum_sum/compare/v0.0.3...master)
4
+
5
+ ### 0.0.3 / 2011-01-27
6
+
7
+ [full changelog](http://github.com/yolk/sum_sum/compare/v0.0.2...v0.0.3)
8
+
9
+ * Added SumSum#dump & SumSum.load methods to dump and load data to serializable objects (array, hash)
4
10
 
5
11
  ### 0.0.2 / 2011-01-27
6
12
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sum_sum (0.0.1)
4
+ sum_sum (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  class SumSum < Hash
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/sum_sum.rb CHANGED
@@ -44,4 +44,32 @@ class SumSum < Hash
44
44
  def inspect
45
45
  bottom? ? "#{count}" : "{#{name}:#{count} #{super.gsub(/^\{|\}$/, "")}}"
46
46
  end
47
+
48
+ def dump
49
+ return count if bottom?
50
+ hash = {}
51
+ each{ |k, v| hash[k] = v.dump }
52
+ root? ? [all_args, hash] : hash
53
+ end
54
+
55
+ def self.load(data)
56
+ new(*data[0]).tap do |sum_sum|
57
+ sum_sum.add_from_dump(data[1])
58
+ end
59
+ end
60
+
61
+ def add_from_dump(data, hash={}, level=0)
62
+ data.each do |key, value|
63
+ hash[all_args[level]] = key
64
+ value.is_a?(Hash) ?
65
+ add_from_dump(value, hash, level + 1) :
66
+ add(hash, value)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def all_args
73
+ [name] + args
74
+ end
47
75
  end
data/spec/sum_sum_spec.rb CHANGED
@@ -40,6 +40,20 @@ describe SumSum do
40
40
  sum[:Browser][:Firefox]["3.6.0"].keys.should eql([])
41
41
  end
42
42
  end
43
+
44
+ context "#dump" do
45
+ it "should output serializable array" do
46
+ sum.dump.should eql(
47
+ [[:type, :name, :version], {:Browser=>{:Firefox=>{"3.6.0"=>1}}}]
48
+ )
49
+ end
50
+ end
51
+
52
+ context ".load" do
53
+ it "should restore everything from serializable array" do
54
+ SumSum.load(sum.dump).dump.should eql(sum.dump)
55
+ end
56
+ end
43
57
  end
44
58
 
45
59
  context "adding multiple hashes" do
@@ -140,6 +154,29 @@ describe SumSum do
140
154
  sum[:Browser][:Firefox].share.should eql(0.25)
141
155
  end
142
156
  end
157
+
158
+ context "#dump" do
159
+ it "should output serializable array" do
160
+ sum.dump.should eql(
161
+ [[:type, :name, :version], {
162
+ :Crawler=>{:GoogleBot=>{"2.0"=>1}},
163
+ :Browser=>{
164
+ :Firefox=>{"3.6.0"=>1},
165
+ :Safari=>{"4.0"=>1, "5.0"=>2}
166
+ }
167
+ }]
168
+ )
169
+ end
170
+ end
171
+
172
+ context ".load" do
173
+ it "should restore everything from serializable array" do
174
+ SumSum.load(sum.dump).dump.should eql(sum.dump)
175
+ end
176
+ end
177
+
143
178
  end
179
+
180
+
144
181
  end
145
182
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sebastian Munz