neatjson 0.6.2 → 0.7

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: 600101c05a890e9aaf85cee5981faf1e8766fe00
4
- data.tar.gz: 7e930b2089416b74b216e8ef16d19403f60abfff
3
+ metadata.gz: d8936fb4141535e1b7ff27991e518e2aa402c592
4
+ data.tar.gz: 9c7eb711499583c719c168cf3f29f443ec900082
5
5
  SHA512:
6
- metadata.gz: a52b419bcd49ea08a13562ba167f9a087fe498f5ca7bbd5804be7ea8a1d02f6880f4f3da8b2a1732ec0211014d8acae32b2238101314be5b7275d0c8022eb820
7
- data.tar.gz: 898b7829d5f7ef031821dedde48f50cdb5364228de69d8406fe315b1aec5b88cab4df21f4ef489d6af6ae93c7d0d8fe0ec1f3b6ae8cdfa9ad8c544b524c07ee7
6
+ metadata.gz: 3e4a1047b1cffdcaa584779dd0e5368d7353ee08272734855ac8249e500734b8bbe6d76cdcb316e2dadde9753b88e58ecb633753cbfca0ab06590aa6847a4ca6
7
+ data.tar.gz: 075950b5e26facacbb8c4b8aeda3b310c8e5cc705578e5e952254f29323ea2fd5c5c5945f011988937848f96104f53df3bf607e7b9a907dc6e3c2d1c7383e64e
data/README.md CHANGED
@@ -1,194 +1,199 @@
1
- # NeatJSON
2
-
3
- [![Gem Version](https://badge.fury.io/rb/neatjson.svg)](http://badge.fury.io/rb/neatjson)
4
- [![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/neatjson?type=total&color=brightgreen)](https://rubygems.org/gems/neatjson)
5
-
6
- Pretty-print your JSON in Ruby with more power than is provided by `JSON.pretty_generate`. In particular, like Ruby's `pp` (pretty print), NeatJSON will keep objects on one line if they fit, but break them over multiple lines if needed.
7
-
8
- Here's an excerpt (from a much larger JSON):
9
-
10
- ~~~ json
11
- {
12
- "navigation.createroute.poi":[
13
- {"text":"Lay in a course to the Hilton","params":{"poi":"Hilton"}},
14
- {"text":"Take me to the airport","params":{"poi":"airport"}},
15
- {"text":"Let's go to IHOP","params":{"poi":"IHOP"}},
16
- {"text":"Show me how to get to The Med","params":{"poi":"The Med"}},
17
- {"text":"Create a route to Arby's","params":{"poi":"Arby's"}},
18
- {
19
- "text":"Go to the Hilton by the Airport",
20
- "params":{"poi":"Hilton","location":"Airport"}
21
- },
22
- {
23
- "text":"Take me to the Fry's in Fresno",
24
- "params":{"poi":"Fry's","location":"Fresno"}
25
- }
26
- ],
27
- "navigation.eta":[
28
- {"text":"When will we get there?"},
29
- {"text":"When will I arrive?"},
30
- {"text":"What time will I get to the destination?"},
31
- {"text":"What time will I reach the destination?"},
32
- {"text":"What time will it be when I arrive?"}
33
- ]
34
- }
35
- ~~~
36
-
37
- ## Installation
38
-
39
- `gem install neatjson`
40
-
41
- ## Examples
42
-
43
- ~~~ ruby
44
- require 'neatjson'
45
-
46
- o = { b:42.005, a:[42,17], longer:true, str:"yes
47
- please" }
48
-
49
- puts JSON.neat_generate(o)
50
- #=> {"b":42.005,"a":[42,17],"longer":true,"str":"yes\nplease"}
51
-
52
- puts JSON.neat_generate(o,sorted:true)
53
- #=> {"a":[42,17],"b":42.005,"longer":true,"str":"yes\nplease"}
54
-
55
- puts JSON.neat_generate(o,sorted:true,padding:1,after_comma:1)
56
- #=> { "a":[ 42, 17 ], "b":42.005, "longer":true, "str":"yes\nplease" }
57
-
58
- puts JSON.neat_generate(o,sorted:true,wrap:40)
59
- #=> {
60
- #=> "a":[42,17],
61
- #=> "b":42.005,
62
- #=> "longer":true,
63
- #=> "str":"yes\nplease"
64
- #=> }
65
-
66
- puts JSON.neat_generate(o,sorted:true,wrap:40,decimals:2)
67
- #=> {
68
- #=> "a":[42,17],
69
- #=> "b":42.01,
70
- #=> "longer":true,
71
- #=> "str":"yes\nplease"
72
- #=> }
73
-
74
- puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true)
75
- #=> {
76
- #=> "a" :[42,17],
77
- #=> "b" :42.005,
78
- #=> "longer":true,
79
- #=> "str" :"yes\nplease"
80
- #=> }
81
-
82
- puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1)
83
- #=> {
84
- #=> "a" : [42,17],
85
- #=> "b" : 42.005,
86
- #=> "longer" : true,
87
- #=> "str" : "yes\nplease"
88
- #=> }
89
-
90
- puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1,short:true)
91
- #=> {"a" : [42,17],
92
- #=> "b" : 42.005,
93
- #=> "longer" : true,
94
- #=> "str" : "yes\nplease"}
95
-
96
- a = [1,2,[3,4,[5]]]
97
- puts JSON.neat_generate(a)
98
- #=> [1,2,[3,4,[5]]]
99
-
100
- puts JSON.pretty_generate(a) # oof!
101
- #=> [
102
- #=> 1,
103
- #=> 2,
104
- #=> [
105
- #=> 3,
106
- #=> 4,
107
- #=> [
108
- #=> 5
109
- #=> ]
110
- #=> ]
111
- #=> ]
112
-
113
- puts JSON.neat_generate( a, wrap:true, short:true )
114
- #=> [1,
115
- #=> 2,
116
- #=> [3,
117
- #=> 4,
118
- #=> [5]]]
119
- ~~~
120
-
121
- ## Options
122
- You may pass any of the following option symbols to `neat_generate`:
123
-
124
- * `:wrap` — The maximum line width before wrapping. Use `false` to never wrap, or `true` (or `-1`) to always wrap. Default: `80`
125
- * `:indent` — Whitespace used to indent each level when wrapping. Default: `" "` (two spaces)
126
- * `:short` Keep the output 'short' when wrapping? This puts opening brackets on the same line as the first value, and closing brackets on the same line as the last. Default: `false`
127
- * _This causes the `:indent` option to be ignored, instead basing indentation on array and object padding._
128
- * `:sorted` — Sort the keys for objects to be in alphabetical order? Default: `false`
129
- * `:aligned` When wrapping objects, line up the colons (per object)? Default: `false`
130
- * `:decimals` Decimal precision to use for non-integer numbers; use `false` to keep float values precise. Default: `false`
131
- * `:array_padding` Number of spaces to put inside brackets for arrays. Default: `0`
132
- * `:object_padding` — Number of spaces to put inside braces for objects. Default: `0`
133
- * `:padding` Shorthand to set both `:array_padding` and `:object_padding`. Default: `0`
134
- * `:before_comma` Number of spaces to put before commas (for both arrays and objects). Default: `0`
135
- * `:after_comma` — Number of spaces to put after commas (for both arrays and objects). Default: `0`
136
- * `:around_comma` Shorthand to set both `:before_comma` and `:after_comma`. Default: `0`
137
- * `:before_colon_1` Number of spaces before a colon when the object is on one line. Default: `0`
138
- * `:after_colon_1` — Number of spaces after a colon when the object is on one line. Default: `0`
139
- * `:before_colon_n` — Number of spaces before a colon when the object is on multiple lines. Default: `0`
140
- * `:after_colon_n` — Number of spaces after a colon when the object is on multiple lines. Default: `0`
141
- * `:before_colon` Shorthand to set both `:before_colon_1` and `:before_colon_n`. Default: `0`
142
- * `:after_colon` — Shorthand to set both `:after_colon_1` and `:after_colon_n`. Default: `0`
143
- * `:around_colon` — Shorthand to set both `:before_colon` and `:after_colon`. Default: `0`
144
-
145
-
146
- ## License & Contact
147
-
148
- NeatJSON is copyright ©2015 by Gavin Kistner and is released under
149
- the [MIT License](http://www.opensource.org/licenses/mit-license.php).
150
- See the LICENSE.txt file for more details.
151
-
152
- For bugs or feature requests please open [issues on GitHub][1].
153
- For other communication you can [email the author directly](mailto:!@phrogz.net?subject=NeatJSON).
154
-
155
- ## TODO (aka Known Limitations)
156
-
157
- * Figure out the best way to play with custom objects that use `to_json` for their representation.
158
- * Detect circular references.
159
- * Possibly allow illegal JSON values like `NaN` or `Infinity`.
160
- * Possibly allow "JSON5" output (legal identifiers unquoted, etc.)
161
-
162
- ## HISTORY
163
-
164
- * **v0.6.1** - October 12th, 2015
165
- * Fix handling of nested empty objects and arrays. (Would cause a runtime error in many cases.)
166
- * _This change causes empty arrays in a tight wrapping scenario to appear on a single line where they would previously take up three lines._
167
-
168
- * **v0.6** - April 26th, 2015
169
- * Added `before_colon_1` and `before_colon_n` to distinguish between single-line and multi-line objects.
170
-
171
- * **v0.5** - April 19th, 2015
172
- * Do not format integers (or floats that equal their integer) using `decimals` option.
173
- * Make `neatJSON()` JavaScript available to Node.js as well as web browsers.
174
- * Add (Node-based) testing for the JavaScript version.
175
-
176
- * **v0.4** - April 18th, 2015
177
- * Add JavaScript version with online runner.
178
-
179
- * **v0.3.2** - April 16th, 2015
180
- * Force YARD to use Markdown for documentation.
181
-
182
- * **v0.3.1** - April 16th, 2015
183
- * Remove some debugging code accidentally left in.
184
-
185
- * **v0.3** - April 16th, 2015
186
- * Fix another bug with `short:true` and wrapping array values inside objects.
187
-
188
- * **v0.2** - April 16th, 2015
189
- * Fix bug with `short:true` and wrapping values inside objects.
190
-
191
- * **v0.1** - April 15th, 2015
192
- * Initial release.
193
-
194
- [1]: https://github.com/Phrogz/NeatJSON/issues
1
+ # NeatJSON
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/neatjson.svg)](http://badge.fury.io/rb/neatjson)
4
+ [![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/neatjson?type=total&color=brightgreen)](https://rubygems.org/gems/neatjson)
5
+
6
+ Pretty-print your JSON in Ruby with more power than is provided by `JSON.pretty_generate`. In particular, like Ruby's `pp` (pretty print), NeatJSON will keep objects on one line if they fit, but break them over multiple lines if needed.
7
+
8
+ Here's an excerpt (from a much larger JSON):
9
+
10
+ ~~~ json
11
+ {
12
+ "navigation.createroute.poi":[
13
+ {"text":"Lay in a course to the Hilton","params":{"poi":"Hilton"}},
14
+ {"text":"Take me to the airport","params":{"poi":"airport"}},
15
+ {"text":"Let's go to IHOP","params":{"poi":"IHOP"}},
16
+ {"text":"Show me how to get to The Med","params":{"poi":"The Med"}},
17
+ {"text":"Create a route to Arby's","params":{"poi":"Arby's"}},
18
+ {
19
+ "text":"Go to the Hilton by the Airport",
20
+ "params":{"poi":"Hilton","location":"Airport"}
21
+ },
22
+ {
23
+ "text":"Take me to the Fry's in Fresno",
24
+ "params":{"poi":"Fry's","location":"Fresno"}
25
+ }
26
+ ],
27
+ "navigation.eta":[
28
+ {"text":"When will we get there?"},
29
+ {"text":"When will I arrive?"},
30
+ {"text":"What time will I get to the destination?"},
31
+ {"text":"What time will I reach the destination?"},
32
+ {"text":"What time will it be when I arrive?"}
33
+ ]
34
+ }
35
+ ~~~
36
+
37
+ ## Installation
38
+
39
+ `gem install neatjson`
40
+
41
+ ## Examples
42
+
43
+ ~~~ ruby
44
+ require 'neatjson'
45
+
46
+ o = { b:42.005, a:[42,17], longer:true, str:"yes
47
+ please" }
48
+
49
+ puts JSON.neat_generate(o)
50
+ #=> {"b":42.005,"a":[42,17],"longer":true,"str":"yes\nplease"}
51
+
52
+ puts JSON.neat_generate(o,sorted:true)
53
+ #=> {"a":[42,17],"b":42.005,"longer":true,"str":"yes\nplease"}
54
+
55
+ puts JSON.neat_generate(o,sorted:true,padding:1,after_comma:1)
56
+ #=> { "a":[ 42, 17 ], "b":42.005, "longer":true, "str":"yes\nplease" }
57
+
58
+ puts JSON.neat_generate(o,sorted:true,wrap:40)
59
+ #=> {
60
+ #=> "a":[42,17],
61
+ #=> "b":42.005,
62
+ #=> "longer":true,
63
+ #=> "str":"yes\nplease"
64
+ #=> }
65
+
66
+ puts JSON.neat_generate(o,sorted:true,wrap:40,decimals:2)
67
+ #=> {
68
+ #=> "a":[42,17],
69
+ #=> "b":42.01,
70
+ #=> "longer":true,
71
+ #=> "str":"yes\nplease"
72
+ #=> }
73
+
74
+ puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true)
75
+ #=> {
76
+ #=> "a" :[42,17],
77
+ #=> "b" :42.005,
78
+ #=> "longer":true,
79
+ #=> "str" :"yes\nplease"
80
+ #=> }
81
+
82
+ puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1)
83
+ #=> {
84
+ #=> "a" : [42,17],
85
+ #=> "b" : 42.005,
86
+ #=> "longer" : true,
87
+ #=> "str" : "yes\nplease"
88
+ #=> }
89
+
90
+ puts JSON.neat_generate(o,sorted:true,wrap:40,aligned:true,around_colon:1,short:true)
91
+ #=> {"a" : [42,17],
92
+ #=> "b" : 42.005,
93
+ #=> "longer" : true,
94
+ #=> "str" : "yes\nplease"}
95
+
96
+ a = [1,2,[3,4,[5]]]
97
+ puts JSON.neat_generate(a)
98
+ #=> [1,2,[3,4,[5]]]
99
+
100
+ puts JSON.pretty_generate(a) # oof!
101
+ #=> [
102
+ #=> 1,
103
+ #=> 2,
104
+ #=> [
105
+ #=> 3,
106
+ #=> 4,
107
+ #=> [
108
+ #=> 5
109
+ #=> ]
110
+ #=> ]
111
+ #=> ]
112
+
113
+ puts JSON.neat_generate( a, wrap:true, short:true )
114
+ #=> [1,
115
+ #=> 2,
116
+ #=> [3,
117
+ #=> 4,
118
+ #=> [5]]]
119
+ ~~~
120
+
121
+ ## Options
122
+ You may pass any of the following option symbols to `neat_generate`:
123
+
124
+ * `:wrap` — The maximum line width before wrapping. Use `false` to never wrap, or `true` (or `-1`) to always wrap. Default: `80`
125
+ * `:indent` — Whitespace used to indent each level when wrapping. Default: `" "` (two spaces)
126
+ * `:indent_last` Indent the closing bracket/brace for arrays and objects? Default: `false`
127
+ * `:short` — Keep the output 'short' when wrapping? This puts opening brackets on the same line as the first value, and closing brackets on the same line as the last. Default: `false`
128
+ * _This causes the `:indent` and `:indent_last` options to be ignored, instead basing indentation on array and object padding._
129
+ * `:sorted` Sort the keys for objects to be in alphabetical order? Default: `false`
130
+ * `:aligned` When wrapping objects, line up the colons (per object)? Default: `false`
131
+ * `:decimals` Decimal precision to use for non-integer numbers; use `false` to keep float values precise. Default: `false`
132
+ * `:array_padding` — Number of spaces to put inside brackets for arrays. Default: `0`
133
+ * `:object_padding` Number of spaces to put inside braces for objects. Default: `0`
134
+ * `:padding` Shorthand to set both `:array_padding` and `:object_padding`. Default: `0`
135
+ * `:before_comma` — Number of spaces to put before commas (for both arrays and objects). Default: `0`
136
+ * `:after_comma` Number of spaces to put after commas (for both arrays and objects). Default: `0`
137
+ * `:around_comma` Shorthand to set both `:before_comma` and `:after_comma`. Default: `0`
138
+ * `:before_colon_1` — Number of spaces before a colon when the object is on one line. Default: `0`
139
+ * `:after_colon_1` — Number of spaces after a colon when the object is on one line. Default: `0`
140
+ * `:before_colon_n` — Number of spaces before a colon when the object is on multiple lines. Default: `0`
141
+ * `:after_colon_n` Number of spaces after a colon when the object is on multiple lines. Default: `0`
142
+ * `:before_colon` — Shorthand to set both `:before_colon_1` and `:before_colon_n`. Default: `0`
143
+ * `:after_colon` — Shorthand to set both `:after_colon_1` and `:after_colon_n`. Default: `0`
144
+ * `:around_colon` — Shorthand to set both `:before_colon` and `:after_colon`. Default: `0`
145
+
146
+
147
+ ## License & Contact
148
+
149
+ NeatJSON is copyright ©2015 by Gavin Kistner and is released under
150
+ the [MIT License](http://www.opensource.org/licenses/mit-license.php).
151
+ See the LICENSE.txt file for more details.
152
+
153
+ For bugs or feature requests please open [issues on GitHub][1].
154
+ For other communication you can [email the author directly](mailto:!@phrogz.net?subject=NeatJSON).
155
+
156
+ ## TODO (aka Known Limitations)
157
+
158
+ * Figure out the best way to play with custom objects that use `to_json` for their representation.
159
+ * Detect circular references.
160
+ * Possibly allow illegal JSON values like `NaN` or `Infinity`.
161
+ * Possibly allow "JSON5" output (legal identifiers unquoted, etc.)
162
+
163
+ ## HISTORY
164
+
165
+ * **v0.6.2** - February 8th, 2016
166
+ * Use memoization to avoid performance stalls when wrapping deeply-nested objects/arrays.
167
+ _Thanks @chroche_
168
+
169
+ * **v0.6.1** - October 12th, 2015
170
+ * Fix handling of nested empty objects and arrays. (Would cause a runtime error in many cases.)
171
+ * _This change causes empty arrays in a tight wrapping scenario to appear on a single line where they would previously take up three lines._
172
+
173
+ * **v0.6** - April 26th, 2015
174
+ * Added `before_colon_1` and `before_colon_n` to distinguish between single-line and multi-line objects.
175
+
176
+ * **v0.5** - April 19th, 2015
177
+ * Do not format integers (or floats that equal their integer) using `decimals` option.
178
+ * Make `neatJSON()` JavaScript available to Node.js as well as web browsers.
179
+ * Add (Node-based) testing for the JavaScript version.
180
+
181
+ * **v0.4** - April 18th, 2015
182
+ * Add JavaScript version with online runner.
183
+
184
+ * **v0.3.2** - April 16th, 2015
185
+ * Force YARD to use Markdown for documentation.
186
+
187
+ * **v0.3.1** - April 16th, 2015
188
+ * Remove some debugging code accidentally left in.
189
+
190
+ * **v0.3** - April 16th, 2015
191
+ * Fix another bug with `short:true` and wrapping array values inside objects.
192
+
193
+ * **v0.2** - April 16th, 2015
194
+ * Fix bug with `short:true` and wrapping values inside objects.
195
+
196
+ * **v0.1** - April 15th, 2015
197
+ * Initial release.
198
+
199
+ [1]: https://github.com/Phrogz/NeatJSON/issues
data/lib/neatjson.rb CHANGED
@@ -6,27 +6,28 @@ module JSON
6
6
  # @author Gavin Kistner <!@phrogz.net>
7
7
  # @param object [Object] the object to serialize
8
8
  # @param opts [Hash] the formatting options
9
- # @option opts [Integer] :wrap (80) The maximum line width before wrapping. Use `false` to never wrap, or `true` to always wrap.
10
- # @option opts [String] :indent (" ") Whitespace used to indent each level when wrapping (without the :short option).
11
- # @option opts [Boolean] :short (false) Keep the output 'short' when wrapping, putting opening brackets on the same line as the first value, and closing brackets on the same line as the last item.
12
- # @option opts [Boolean] :sorted (false) Sort the keys for objects to be in alphabetical order.
13
- # @option opts [Boolean] :aligned (false) When wrapping objects, align the colons (only per object).
14
- # @option opts [Integer] :decimals (null) Decimal precision to use for floats; omit to keep numberic values precise.
15
- # @option opts [Integer] :padding (0) Number of spaces to put inside brackets/braces for both arrays and objects.
16
- # @option opts [Integer] :array_padding (0) Number of spaces to put inside brackets for arrays. Overrides `:padding`.
17
- # @option opts [Integer] :object_padding (0) Number of spaces to put inside braces for objects. Overrides `:padding`.
18
- # @option opts [Integer] :around_comma (0) Number of spaces to put before/after commas (for both arrays and objects).
19
- # @option opts [Integer] :before_comma (0) Number of spaces to put before commas (for both arrays and objects).
20
- # @option opts [Integer] :after_comma (0) Number of spaces to put after commas (for both arrays and objects).
21
- # @option opts [Integer] :around_colon (0) Number of spaces to put before/after colons (for objects).
22
- # @option opts [Integer] :before_colon (0) Number of spaces to put before colons (for objects).
23
- # @option opts [Integer] :after_colon (0) Number of spaces to put after colons (for objects).
24
- # @option opts [Integer] :around_colon_1 (0) Number of spaces to put before/after colons for single-line objects.
25
- # @option opts [Integer] :before_colon_1 (0) Number of spaces to put before colons for single-line objects.
26
- # @option opts [Integer] :after_colon_1 (0) Number of spaces to put after colons for single-line objects.
27
- # @option opts [Integer] :around_colon_n (0) Number of spaces to put before/after colons for multi-line objects.
28
- # @option opts [Integer] :before_colon_n (0) Number of spaces to put before colons for multi-line objects.
29
- # @option opts [Integer] :after_colon_n (0) Number of spaces to put after colons for multi-line objects.
9
+ # @option opts [Integer] :wrap (80) The maximum line width before wrapping. Use `false` to never wrap, or `true` to always wrap.
10
+ # @option opts [String] :indent (" ") Whitespace used to indent each level when wrapping (without the :short option).
11
+ # @option opts [Boolean] :indent_last (false) Indent the closing bracket for arrays and objects (without the :short option).
12
+ # @option opts [Boolean] :short (false) Keep the output 'short' when wrapping, putting opening brackets on the same line as the first value, and closing brackets on the same line as the last item.
13
+ # @option opts [Boolean] :sorted (false) Sort the keys for objects to be in alphabetical order.
14
+ # @option opts [Boolean] :aligned (false) When wrapping objects, align the colons (only per object).
15
+ # @option opts [Integer] :decimals (null) Decimal precision to use for floats; omit to keep numberic values precise.
16
+ # @option opts [Integer] :padding (0) Number of spaces to put inside brackets/braces for both arrays and objects.
17
+ # @option opts [Integer] :array_padding (0) Number of spaces to put inside brackets for arrays. Overrides `:padding`.
18
+ # @option opts [Integer] :object_padding (0) Number of spaces to put inside braces for objects. Overrides `:padding`.
19
+ # @option opts [Integer] :around_comma (0) Number of spaces to put before/after commas (for both arrays and objects).
20
+ # @option opts [Integer] :before_comma (0) Number of spaces to put before commas (for both arrays and objects).
21
+ # @option opts [Integer] :after_comma (0) Number of spaces to put after commas (for both arrays and objects).
22
+ # @option opts [Integer] :around_colon (0) Number of spaces to put before/after colons (for objects).
23
+ # @option opts [Integer] :before_colon (0) Number of spaces to put before colons (for objects).
24
+ # @option opts [Integer] :after_colon (0) Number of spaces to put after colons (for objects).
25
+ # @option opts [Integer] :around_colon_1 (0) Number of spaces to put before/after colons for single-line objects.
26
+ # @option opts [Integer] :before_colon_1 (0) Number of spaces to put before colons for single-line objects.
27
+ # @option opts [Integer] :after_colon_1 (0) Number of spaces to put after colons for single-line objects.
28
+ # @option opts [Integer] :around_colon_n (0) Number of spaces to put before/after colons for multi-line objects.
29
+ # @option opts [Integer] :before_colon_n (0) Number of spaces to put before colons for multi-line objects.
30
+ # @option opts [Integer] :after_colon_n (0) Number of spaces to put after colons for multi-line objects.
30
31
  # @return [String] the JSON representation of the object.
31
32
  def self.neat_generate(object,opts={})
32
33
  opts[:wrap] = 80 unless opts.key?(:wrap)
@@ -80,7 +81,7 @@ module JSON
80
81
  pieces.join ",\n"
81
82
  else
82
83
  indent2 = "#{indent}#{opts[:indent]}"
83
- "#{indent}[\n#{o.map{ |v| build[ v, indent2 ] }.join ",\n"}\n#{indent}]"
84
+ "#{indent}[\n#{o.map{ |v| build[ v, indent2 ] }.join ",\n"}\n#{opts[:indent_last] ? indent2 : indent}]"
84
85
  end
85
86
 
86
87
  when Hash
@@ -126,7 +127,7 @@ module JSON
126
127
  one_line
127
128
  end
128
129
  end
129
- "#{indent}{\n#{keyvals.join(",\n")}\n#{indent}}"
130
+ "#{indent}{\n#{keyvals.join(",\n")}\n#{opts[:indent_last] ? indent2 : indent}}"
130
131
  end
131
132
  end
132
133