steamroller 1.0.0 → 1.1.1
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/VERSION +1 -1
- data/lib/steamroller.rb +13 -13
- data/steamroller.gemspec +2 -2
- data/test/test_steamroller.rb +2 -4
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/lib/steamroller.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
class
|
2
|
-
def
|
3
|
-
flat =
|
1
|
+
class Hash
|
2
|
+
def flatten(joiner=".", &block)
|
3
|
+
flat = combine_keys(self, joiner, [], &block).flatten
|
4
4
|
Hash[*flat.map {|f| f.to_a}.flatten]
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
7
|
+
private
|
8
|
+
def combine_keys(data, joiner=".", prefix=[], &block)
|
9
|
+
if data.respond_to?(:keys)
|
10
|
+
data.keys.collect do |key|
|
11
|
+
combine_keys(data[key], joiner, [prefix, key], &block)
|
12
|
+
end.flatten
|
13
|
+
else
|
14
|
+
return nil if block_given? && !yield(data)
|
15
|
+
[prefix.flatten.join(joiner) => data]
|
17
16
|
end
|
17
|
+
end
|
18
18
|
end
|
data/steamroller.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{steamroller}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian Meyer"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-07}
|
13
13
|
s.description = %q{Steamroll a nested hash into a singular hash delimiting keys by a period.}
|
14
14
|
s.email = %q{ianmmeyer@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_steamroller.rb
CHANGED
@@ -7,13 +7,11 @@ class TestSteamroller < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
should "flatten out nicely" do
|
10
|
-
|
11
|
-
assert_equal Hash["c.d"=>14, "a.b"=>3], @flattened
|
10
|
+
assert_equal Hash["c.d"=>14, "a.b"=>3], @data.flatten
|
12
11
|
end
|
13
12
|
|
14
13
|
should "flatten out nicely with a | as the delimiter" do
|
15
|
-
|
16
|
-
assert_equal Hash["c|d"=>14, "a|b"=>3], @flattened
|
14
|
+
assert_equal Hash["c|d"=>14, "a|b"=>3], @data.flatten('|')
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steamroller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ian Meyer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|