tidy_json 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -32
- data/lib/tidy_json/dedication.rb +3 -1
- data/lib/tidy_json/version.rb +3 -1
- data/lib/tidy_json.rb +15 -2
- data/tidy_json.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee82014d81eee49d6386266ea0b95ac1774291db69bdc50e32a062b7e39613e
|
4
|
+
data.tar.gz: fa30e666d9762736b9f61e89ce94b0ab2384df7cc7b011dd21114399d88b56e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fe08f848f90052cef2c6cff40c56cd9abd7afefc9d8998091d64fa6a8f710df2682f4c7c17eac9bbdb9185b5418e7da7ecfb6e8a1f82a860b4faaa481bfb97c
|
7
|
+
data.tar.gz: 3b6c7bbb72b216e9759f2c822ad35e206b41faafa21f3f9eb5bb79313008ba64562d99159d1f6e2e1485e9833e8a2f7916a8c8d1a307ab929b1f77f7f32a878d
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ gem 'tidy_json'
|
|
24
24
|
```ruby
|
25
25
|
require 'tidy_json'
|
26
26
|
|
27
|
-
class
|
27
|
+
class Jsonable
|
28
28
|
attr_reader :a, :b
|
29
29
|
def initialize
|
30
30
|
@a = { a: 'uno', b: 'dos', c: ['I', 'II', 'III', ['i.', 'ii.', 'iii.', { 'ichi': "\u{4e00}", 'ni': "\u{4e8c}", 'san': "\u{4e09}", 'yon': "\u{56db}" }]] }
|
@@ -32,42 +32,42 @@ class JsonableObject
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
my_jsonable =
|
35
|
+
my_jsonable = Jsonable.new
|
36
36
|
|
37
37
|
JSON.parse my_jsonable.stringify
|
38
38
|
# => {"class"=>"Jsonable", "a"=>{"a"=>"uno", "b"=>"dos", "c"=>["I", "II", "III", ["i.", "ii.", "iii.", {"ichi"=>"一", "ni"=>"二", "san"=>"三", "yon"=>"四"}]]}, "b"=>{"a"=>1, "b"=>["two", 3, "<abbr title=\"four\">IV</abbr>"]}}
|
39
39
|
|
40
|
-
puts my_jsonable.to_tidy_json(indent:
|
40
|
+
puts my_jsonable.to_tidy_json(indent: 4)
|
41
41
|
# {
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
42
|
+
# "class": "Jsonable",
|
43
|
+
# "a": {
|
44
|
+
# "a": "uno",
|
45
|
+
# "b": "dos",
|
46
|
+
# "c": [
|
47
|
+
# "I",
|
48
|
+
# "II",
|
49
|
+
# "III",
|
50
|
+
# [
|
51
|
+
# "i.",
|
52
|
+
# "ii.",
|
53
|
+
# "iii.",
|
54
|
+
# {
|
55
|
+
# "ichi": "一",
|
56
|
+
# "ni": "二",
|
57
|
+
# "san": "三",
|
58
|
+
# "yon": "四"
|
59
|
+
# }
|
60
|
+
# ]
|
61
|
+
# ]
|
62
|
+
# },
|
63
|
+
# "b": {
|
64
|
+
# "a": 1,
|
65
|
+
# "b": [
|
66
|
+
# "two",
|
67
|
+
# 3,
|
68
|
+
# "<abbr title=\"four\">IV</abbr>"
|
69
|
+
# ]
|
70
|
+
# }
|
71
71
|
# }
|
72
72
|
# => nil
|
73
73
|
```
|
data/lib/tidy_json/dedication.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TidyJson # :nodoc:
|
2
4
|
DEDICATION = "\n#{'.' * 50}\n#{'.' * 19} IN MEMORIAM #{'.' * 18}\n" \
|
3
5
|
"#{'.' * 16} Michael Di Pardo #{'.' * 16}\n" \
|
@@ -6,5 +8,5 @@ module TidyJson # :nodoc:
|
|
6
8
|
"#{'.' * 11} Please consider supporting #{'.' * 11}\n" \
|
7
9
|
"#{'.' * 13} the MS Society of Canada #{'.' * 11}\n" \
|
8
10
|
"#{'.' * 8} https://mssociety.ca/get-involved #{'.' * 7}\n" \
|
9
|
-
"#{'.' * 50}\n\n"
|
11
|
+
"#{'.' * 50}\n\n"
|
10
12
|
end
|
data/lib/tidy_json/version.rb
CHANGED
data/lib/tidy_json.rb
CHANGED
@@ -74,7 +74,7 @@ module TidyJson
|
|
74
74
|
# Writes a JSON representation of the sender object to the file specified by +out+.
|
75
75
|
#
|
76
76
|
# @param out [String] The destination filename.
|
77
|
-
# @param opts [Hash] Formatting options for this object's +#to_tidy_json+ method.
|
77
|
+
# @param opts [Hash] Formatting options for this object's +#to_tidy_json+ method, when called.
|
78
78
|
# [:tidy] whether or not the output should be pretty-printed
|
79
79
|
# [:indent] the number of white spaces to indent
|
80
80
|
# @return [String, nil] The path to the written output file, if successful.
|
@@ -82,7 +82,16 @@ module TidyJson
|
|
82
82
|
path = nil
|
83
83
|
|
84
84
|
File.open("#{out}.json", 'w') do |f|
|
85
|
-
path =
|
85
|
+
path =
|
86
|
+
f << if !instance_variables.empty?
|
87
|
+
if opts[:tidy] then to_tidy_json(opts)
|
88
|
+
else stringify
|
89
|
+
end
|
90
|
+
else
|
91
|
+
if opts[:tidy] then to_tidy_json(opts)
|
92
|
+
else to_json
|
93
|
+
end
|
94
|
+
end
|
86
95
|
end
|
87
96
|
|
88
97
|
path.path
|
@@ -245,6 +254,10 @@ module TidyJson
|
|
245
254
|
# @!attribute indent
|
246
255
|
# @return [String] the string of white space used by this +Formatter+ to indent object members.
|
247
256
|
|
257
|
+
##
|
258
|
+
# Returns a new instance of +Formatter+.
|
259
|
+
# @param format_options [Hash] Formatting options.
|
260
|
+
# [:indent] the number of white spaces to indent. The default is 2.
|
248
261
|
def initialize(format_options = {})
|
249
262
|
##
|
250
263
|
# The number of times to reduce the left indent of a nested array's opening
|
data/tidy_json.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Robert Di Pardo']
|
11
11
|
spec.email = 'rdipardo0520@conestogac.on.ca'
|
12
12
|
spec.homepage = 'https://github.com/rdipardo/tidy_json'
|
13
|
-
spec.metadata = { 'documentation_uri' => 'https://rubydoc.org/github/rdipardo/tidy_json
|
13
|
+
spec.metadata = { 'documentation_uri' => 'https://rubydoc.org/github/rdipardo/tidy_json' }
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
16
16
|
['.yardopts'].concat(`git ls-files -z`.split("\x0").reject { |f| f.match(/^(\.[\w+\.]+|test|spec|features)/) })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidy_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Di Pardo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -72,7 +72,7 @@ homepage: https://github.com/rdipardo/tidy_json
|
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
74
|
metadata:
|
75
|
-
documentation_uri: https://rubydoc.org/github/rdipardo/tidy_json
|
75
|
+
documentation_uri: https://rubydoc.org/github/rdipardo/tidy_json
|
76
76
|
post_install_message: |2+
|
77
77
|
|
78
78
|
..................................................
|