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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a874be0629fb8b05f091435d8589d5d789a44865
4
- data.tar.gz: 55d8f97a15fbcab3fd4022a8639d0d386e59e511
3
+ metadata.gz: 3062690d7f47d6c5294c379941cc4638495879a6
4
+ data.tar.gz: 7ff998fe639a348f1c4b3a15a8003c8246764014
5
5
  SHA512:
6
- metadata.gz: e3146a94f973371a2d2091449282393eabffeed605279bd2c8876c27d6a4a430d4a986ffb1f417cf10ccdc9b5431916dccd5ad18a04bc232d1e38bff19132388
7
- data.tar.gz: c7b0f974840341d988c36d0ddc0160f57850951ecc1d0055643968e90c360c9d2aeb675cd9373d0f88d3b2c2b44fc5ff4104a3ea85cb38221d37b68a07752740
6
+ metadata.gz: 5d6c02ed1b8bc9b78b79d6008ea9bc58d9f4ac82769a7ab6fd7e5c6acaad4ccdfb2259bb9e9dfaad7d19cae1e32b82834eefd7e9c10259259a4048f347867311
7
+ data.tar.gz: bbaf0cc3b31ba54a020a9fd8985201040f3e64832d7d1bc53c648ebff667bfd3372ded56e7ce56adf90d9b088bae9cc7e58890f2d0e4e70aea2634293888dfa9
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0 (2016-11-06)
2
+
3
+ * Add `TJSON.pretty_generate`
4
+
1
5
  ## 0.2.0 (2016-11-06)
2
6
 
3
7
  * Complete rewrite to support new postfix syntax
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
- >> puts TJSON.generate({"foo" => "bar"})
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
@@ -59,12 +59,21 @@ module TJSON
59
59
  object
60
60
  end
61
61
 
62
- # Generate TJSON from a Ruby Hash or Array
62
+ # Generate TJSON from a Ruby Hash (TJSON only allows objects as toplevel values)
63
63
  #
64
- # @param obj [Array, Hash] Ruby Hash or Array to serialize as TJSON
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TJSON
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tjson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri