data_list_converter 0.3.9 → 0.3.10

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: 2ecbbb8c5d6e3ad1e2de6f3b4a8fc5033cdc83ff
4
- data.tar.gz: f4b8eb65bf43e3f28ed3607b06f5643eb278b4a4
3
+ metadata.gz: 85c9410c6b8c64a1af696f42485e098f43f432c2
4
+ data.tar.gz: 930b7bb74e9d441e183451d4329e639c06aa3cdf
5
5
  SHA512:
6
- metadata.gz: ea3669bc7a3bb7e381387538433bad76401ffe288d3dd54d2d7181797719951b138db9810fc98ac1460361fa3b25b6924d040c06f3cb19bb54db4bc43545b718
7
- data.tar.gz: 159e246ba2bc8e83b0b699d4a503328bd2ddd2d5792cabaea6c541388f705d0d41a62b3c06fd09a1e6aceac3d1d7fb4632798a847d273fc2ab9c963524d44601
6
+ metadata.gz: b53cb6e80ac57b256b74100421b12d14c9e1f57bee172807bb0f6437efe27e2c2c8915705d52b0e1ff01855188a6e4a3ac274138f7623cbec648a187ba349631
7
+ data.tar.gz: c87df4a93536be36f7aec7d88c3c93325b39fe03ab09414d4d1533024569e6d550f46cfff724df48bd39612bd6b52727473acbe20b1fdd273b92194b4f9286fc
data/README.md CHANGED
@@ -99,6 +99,7 @@ end
99
99
  ## Todo
100
100
 
101
101
  - check type exists
102
+ - route not found, list all routes
102
103
  - register can bind method again
103
104
  - better API
104
105
  - better error message
data/changelog.md CHANGED
@@ -8,6 +8,7 @@ Refactor.
8
8
  - 0.3.7 add marshal_file type, and load_from_file, save_to_file helper
9
9
  - 0.3.8 add raw type
10
10
  - 0.3.9 add unify_item_data_keys helper
11
+ - 0.3.10 add flatten
11
12
 
12
13
  ## 0.2
13
14
 
@@ -46,4 +46,27 @@ class DataListConverter
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ # flatten multi level item data into one level, example:
51
+ # {a: {b: 12}, c: {d: {e: 11}}}
52
+ # =>
53
+ # {:"a:b"=>12, :"c:d:e"=>11}
54
+ def self.flatten(data, sep=':')
55
+ out = {}
56
+ recursive_flatten(out, data, nil, sep)
57
+ out
58
+ end
59
+
60
+ def self.recursive_flatten(out, data, header, sep)
61
+ data.each do |k, v|
62
+ k = header ? :"#{header}#{sep}#{k}" : k
63
+ case v
64
+ when Hash
65
+ recursive_flatten(out, v, k, sep)
66
+ else
67
+ out[k] = v
68
+ end
69
+ end
70
+ end
71
+
49
72
  end
@@ -1,3 +1,3 @@
1
1
  class DataListConverter
2
- VERSION = "0.3.9".freeze
2
+ VERSION = "0.3.10".freeze
3
3
  end
data/test/helper_test.rb CHANGED
@@ -70,4 +70,15 @@ describe DataListConverter do
70
70
  end
71
71
  end
72
72
 
73
+
74
+ describe :flatten do
75
+ specify do
76
+ data = {a: {b: 12}, c: {d: {e: 11}}}
77
+ @c.flatten(data).must_equal({:"a:b"=>12, :"c:d:e"=>11})
78
+
79
+ # change sep
80
+ data = {a: {b: 12}, c: {d: {e: 11}}}
81
+ @c.flatten(data, '_').must_equal({:"a_b"=>12, :"c_d_e"=>11})
82
+ end
83
+ end
73
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_list_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - linjunhalida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake