any2tmx 1.0.2 → 1.0.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.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/lib/any2tmx/transforms/yaml_transform.rb +1 -1
- data/lib/any2tmx/traversable.rb +78 -13
- data/lib/any2tmx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 254e2e49f9066afc36e3680b124e270f39aeffcf
|
4
|
+
data.tar.gz: 4c98b41da4be3aea62dc8c3ee708e340caf493d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 393d789effc3dc7ec69e7d6ed672999c70a8000a314e91d8d8abdae771e64f1a324778625ab9f93067432e11c6904e767a588aadd5ebf4e3dd95f5f49e1e660a
|
7
|
+
data.tar.gz: d459eca4642a71e6ca71fc1599c2be0cf329f37a72162cbebb960fb212478f179bec612f46cdba032c0fd68345fbd77226ab17856c4b97b41ad4f60679710fc4
|
data/History.txt
CHANGED
data/lib/any2tmx/traversable.rb
CHANGED
@@ -8,7 +8,9 @@ module Any2Tmx
|
|
8
8
|
|
9
9
|
def each_entry(&block)
|
10
10
|
if block_given?
|
11
|
-
each_entry_helper(collection, [],
|
11
|
+
each_entry_helper(collection, [], nil) do |entry, path, last_key|
|
12
|
+
yield entry, path + [last_key]
|
13
|
+
end
|
12
14
|
else
|
13
15
|
to_enum(__method__)
|
14
16
|
end
|
@@ -18,17 +20,46 @@ module Any2Tmx
|
|
18
20
|
each_entry.inject(0) { |ret, _| ret + 1 }
|
19
21
|
end
|
20
22
|
|
23
|
+
def dig_each(path)
|
24
|
+
if block_given?
|
25
|
+
path.inject(:start) do |ret, seg|
|
26
|
+
if ret == :start
|
27
|
+
yield collection, seg
|
28
|
+
collection[seg]
|
29
|
+
elsif ret
|
30
|
+
if seg.is_a?(Numeric) && ret.is_a?(Array)
|
31
|
+
yield ret, seg
|
32
|
+
ret[seg] # array index case
|
33
|
+
elsif ret.is_a?(Hash)
|
34
|
+
yield ret, seg
|
35
|
+
ret[seg] # hash key case
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
to_enum(__method__, path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
21
44
|
def dig(path)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
45
|
+
return collection if path.empty?
|
46
|
+
dig_each(path) {}
|
47
|
+
end
|
48
|
+
|
49
|
+
def transform
|
50
|
+
if block_given?
|
51
|
+
self.class.new(make_empty(sym_from(collection))).tap do |copy|
|
52
|
+
each_entry_helper(collection, [], nil) do |entry, path, last_key|
|
53
|
+
dig_each(path).inject(copy.collection) do |copy_obj, (obj, key)|
|
54
|
+
copy_obj[key] ||= make_empty(sym_from(obj[key]))
|
55
|
+
copy_obj[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
yield copy.dig(path), last_key, entry
|
30
59
|
end
|
31
60
|
end
|
61
|
+
else
|
62
|
+
to_enum(__method__)
|
32
63
|
end
|
33
64
|
end
|
34
65
|
|
@@ -40,22 +71,56 @@ module Any2Tmx
|
|
40
71
|
end
|
41
72
|
end
|
42
73
|
|
74
|
+
def stringify_keys
|
75
|
+
transform do |obj, key, value|
|
76
|
+
obj[stringify(key)] = value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
43
80
|
private
|
44
81
|
|
45
|
-
def
|
82
|
+
def stringify(obj)
|
83
|
+
obj.is_a?(Symbol) ? obj.to_s : obj
|
84
|
+
end
|
85
|
+
|
86
|
+
def sym_from(obj)
|
87
|
+
case obj
|
88
|
+
when Hash
|
89
|
+
:hash
|
90
|
+
when Array
|
91
|
+
:array
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def make_empty(sym)
|
96
|
+
case sym
|
97
|
+
when :hash
|
98
|
+
{}
|
99
|
+
when :array
|
100
|
+
[]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def each_entry_helper(coll, path, last_key, &block)
|
105
|
+
next_path = if last_key
|
106
|
+
path + [last_key]
|
107
|
+
else
|
108
|
+
path
|
109
|
+
end
|
110
|
+
|
46
111
|
case coll
|
47
112
|
when Hash
|
48
113
|
coll.each_pair do |key, value|
|
49
|
-
each_entry_helper(value,
|
114
|
+
each_entry_helper(value, next_path, key, &block)
|
50
115
|
end
|
51
116
|
|
52
117
|
when Array
|
53
118
|
coll.each_with_index do |element, idx|
|
54
|
-
each_entry_helper(element,
|
119
|
+
each_entry_helper(element, next_path, idx, &block)
|
55
120
|
end
|
56
121
|
|
57
122
|
when String
|
58
|
-
yield coll, path
|
123
|
+
yield coll, path, last_key
|
59
124
|
end
|
60
125
|
end
|
61
126
|
end
|
data/lib/any2tmx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: any2tmx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xml-write-stream
|