tjson 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +18 -1
- data/lib/tjson.rb +11 -2
- data/lib/tjson/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3062690d7f47d6c5294c379941cc4638495879a6
|
4
|
+
data.tar.gz: 7ff998fe639a348f1c4b3a15a8003c8246764014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d6c02ed1b8bc9b78b79d6008ea9bc58d9f4ac82769a7ab6fd7e5c6acaad4ccdfb2259bb9e9dfaad7d19cae1e32b82834eefd7e9c10259259a4048f347867311
|
7
|
+
data.tar.gz: bbaf0cc3b31ba54a020a9fd8985201040f3e64832d7d1bc53c648ebff667bfd3372ded56e7ce56adf90d9b088bae9cc7e58890f2d0e4e70aea2634293888dfa9
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -55,10 +55,27 @@ The following describes how TJSON types map onto Ruby types during parsing:
|
|
55
55
|
To generate TJSON from Ruby objects, use the `TJSON.generate` method:
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
|
58
|
+
puts TJSON.generate({"foo" => "bar"})
|
59
59
|
{"foo:s:"bar"}
|
60
60
|
```
|
61
61
|
|
62
|
+
For better formatting, use the `TJSON.pretty_generate` method:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
puts TJSON.pretty_generate({"array-example" => [{"string-example" => "foobar", "binary-example" => "BINARY".encode(Encoding::BINARY), "float-example" => 0.42, "int-example" => 42, "timestamp-example" => Time.now}]})
|
66
|
+
{
|
67
|
+
"array-example:A<O>": [
|
68
|
+
{
|
69
|
+
"string-example:s": "foobar",
|
70
|
+
"binary-example:b64": "QklOQVJZ",
|
71
|
+
"float-example:f": 0.42,
|
72
|
+
"int-example:i": "42",
|
73
|
+
"timestamp-example:t": "2016-11-06T22:27:34Z"
|
74
|
+
}
|
75
|
+
]
|
76
|
+
}
|
77
|
+
```
|
78
|
+
|
62
79
|
## Contributing
|
63
80
|
|
64
81
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tjson/tjson-ruby
|
data/lib/tjson.rb
CHANGED
@@ -59,12 +59,21 @@ module TJSON
|
|
59
59
|
object
|
60
60
|
end
|
61
61
|
|
62
|
-
# Generate TJSON from a Ruby Hash
|
62
|
+
# Generate TJSON from a Ruby Hash (TJSON only allows objects as toplevel values)
|
63
63
|
#
|
64
|
-
# @param obj [
|
64
|
+
# @param obj [Hash] Ruby Hash to serialize as TJSON
|
65
65
|
# @return [String] serialized TJSON
|
66
66
|
def self.generate(obj)
|
67
67
|
raise TypeError, "toplevel type must be a Hash" unless obj.is_a?(Hash)
|
68
68
|
JSON.generate(TJSON::DataType.generate(obj))
|
69
69
|
end
|
70
|
+
|
71
|
+
# Generate TJSON from a Ruby Hash (TJSON only allows objects as toplevel values)
|
72
|
+
#
|
73
|
+
# @param obj [Hash] Ruby Hash to serialize as TJSON
|
74
|
+
# @return [String] serialized TJSON
|
75
|
+
def self.pretty_generate(obj)
|
76
|
+
raise TypeError, "toplevel type must be a Hash" unless obj.is_a?(Hash)
|
77
|
+
JSON.pretty_generate(TJSON::DataType.generate(obj))
|
78
|
+
end
|
70
79
|
end
|
data/lib/tjson/version.rb
CHANGED