vidibus-core_extensions 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -72,16 +72,26 @@ class Hash
72
72
  end
73
73
 
74
74
  # Returns a nested array. Just like #to_a, but nested.
75
+ # Also converts hashes within arrays.
75
76
  #
76
77
  def to_a_rec
77
78
  array = []
78
79
  for key, value in self
79
- value = value.to_a_rec if value.is_a?(Hash)
80
+ if value.is_a?(Hash)
81
+ value = value.to_a_rec
82
+ elsif value.is_a?(Array)
83
+ a = value.flatten
84
+ value = []
85
+ for v in a
86
+ value << (v.is_a?(Hash) ? v.to_a_rec : v)
87
+ end
88
+ end
80
89
  array << [key, value]
81
90
  end
82
91
  array
83
92
  end
84
93
 
94
+
85
95
  # Returns true if hash has all of given keys.
86
96
  # It's like Hash#key?, but it accepts several keys.
87
97
  #
@@ -59,10 +59,15 @@ describe "Vidibus::CoreExtensions::Hash" do
59
59
  hash.to_a_rec.should eql([[:some, "thing"]])
60
60
  end
61
61
 
62
- it "should return an array of from nested attributes" do
62
+ it "should return an array from nested hashes" do
63
63
  hash = {:some => {:nested => {:is => ["really", "groovy"]}}}
64
64
  hash.to_a_rec.should eql([[:some, [[:nested, [[:is, ["really", "groovy"]]]]]]])
65
65
  end
66
+
67
+ it "should return an array from hashes within arrays" do
68
+ hash = {:some => [:nested, {:is => ["really", "groovy"]}]}
69
+ hash.to_a_rec.should eql([[:some, [:nested, [[:is, ["really", "groovy"]]]]]])
70
+ end
66
71
  end
67
72
 
68
73
  describe "#keys?" do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vidibus-core_extensions}
8
- s.version = "0.3.7"
8
+ s.version = "0.3.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Pankratz"]
12
- s.date = %q{2010-09-27}
12
+ s.date = %q{2010-10-04}
13
13
  s.description = %q{Provides some extensions to the ruby core.}
14
14
  s.email = %q{andre@vidibus.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-27 00:00:00 +02:00
18
+ date: 2010-10-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21