recursive-open-struct 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,17 +3,17 @@
3
3
  RecursiveOpenStruct is a extension of OpenStruct.
4
4
  It enhance OpenStruct in that it allows nested hashes to be treated in a recursive
5
5
  fashion. For example:
6
+ ros = RecursiveOpenStruct.new( { :fooa => { :foob => 'fooc' } } )
7
+ can now be accessed this way :
8
+ ros.fooa.foob # 'fooc'
6
9
 
7
- ros = RecursiveOpenStruct.new({ :a => { :b => 'c' } })
8
- ros.a.b # 'c'
10
+ Also, if needed, nested hashes can still be accessed as hashes :
9
11
 
10
- Also, nested hashes can still be accessed as hashes:
11
-
12
- ros.a_as_a_hash # { :b => 'c' }
12
+ ros.fooa_as_a_hash # { :foob => 'fooc' }
13
13
 
14
14
  == Installation
15
15
 
16
- So easy.
16
+ Available as a gem in rubygems, the default gem repository.
17
17
 
18
18
  If you use bundler, just throw that in your gemfile :
19
19
  gem 'recursive-open-struct'
@@ -21,6 +21,8 @@ If you use bundler, just throw that in your gemfile :
21
21
  You may also install the gem manually :
22
22
  gem install recursive-open-struct
23
23
 
24
+ Isn't that easy ? (Special thanks to the jeweler tool)
25
+
24
26
  == Note on Patches/Pull Requests
25
27
 
26
28
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -32,13 +32,20 @@ class RecursiveOpenStruct < OpenStruct
32
32
  ostrct_or_hash = ostrct_or_hash.marshal_dump
33
33
  end
34
34
 
35
- data_indent = ostrct_or_hash.max {|a,b| a[0].to_s.length <=> b[0].to_s.length}[0].length
35
+ # We'll display the key values like this : key = value
36
+ # to align display, we look for the maximum key length of the data that will be displayed
37
+ # (everything except hashes)
38
+ data_indent = ostrct_or_hash
39
+ .reject { |k, v| v.is_a?(RecursiveOpenStruct) || v.is_a?(Hash) }
40
+ .max {|a,b| a[0].to_s.length <=> b[0].to_s.length}[0].length
41
+ # puts "max length = #{data_indent}"
42
+
36
43
  ostrct_or_hash.each do |key, value|
37
44
  if (value.is_a?(RecursiveOpenStruct) || value.is_a?(Hash)) then
38
45
  puts ' '*indent_level + key.to_s + '.'
39
46
  display_recursive_open_struct(value, indent_level + 1, recursion_limit - 1)
40
47
  else
41
- puts ' '*indent_level + key.to_s + ' '*(data_indent - key.to_s.length) + '= ' + value.inspect
48
+ puts ' '*indent_level + key.to_s + ' '*(data_indent - key.to_s.length) + ' = ' + value.inspect
42
49
  end
43
50
  end
44
51
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{recursive-open-struct}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{William (B.J.) Snow Orvis}]
12
- s.date = %q{2011-05-25}
12
+ s.date = %q{2011-05-31}
13
13
  s.description = %q{RecursiveOpenStruct is a subclass of OpenStruct. It differs from
14
14
  OpenStruct in that it allows nested hashes to be treated in a recursive
15
15
  fashion. For example:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-25 00:00:00.000000000Z
12
+ date: 2011-05-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &74135210 !ruby/object:Gem::Requirement
16
+ requirement: &73346940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *74135210
24
+ version_requirements: *73346940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &74134960 !ruby/object:Gem::Requirement
27
+ requirement: &73346640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *74134960
35
+ version_requirements: *73346640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &74134720 !ruby/object:Gem::Requirement
38
+ requirement: &73346350 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *74134720
46
+ version_requirements: *73346350
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &74134480 !ruby/object:Gem::Requirement
49
+ requirement: &73346110 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *74134480
57
+ version_requirements: *73346110
58
58
  description: ! "RecursiveOpenStruct is a subclass of OpenStruct. It differs from\nOpenStruct
59
59
  in that it allows nested hashes to be treated in a recursive\nfashion. For example:\n\n
60
60
  \ ros = RecursiveOpenStruct.new({ :a => { :b => 'c' } })\n ros.a.b # 'c'\n\nAlso,
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: 914381613
97
+ hash: 764807215
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  none: false
100
100
  requirements: