json_builder 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,7 +82,7 @@ module JSONBuilder
82
82
  def type_cast(text)
83
83
  case text
84
84
  when Array then '['+ text.map! { |j| type_cast(j) }.join(', ') +']'
85
- when Hash then 'teheh'
85
+ when Hash then loop_hash(text)
86
86
  when String then "\"#{text}\""
87
87
  when TrueClass then 'true'
88
88
  when FalseClass then 'false'
@@ -91,6 +91,16 @@ module JSONBuilder
91
91
  when Fixnum, Bignum then text
92
92
  end
93
93
  end
94
+
95
+ def loop_hash(hash)
96
+ compiled_hash = []
97
+
98
+ hash.each do |key, value|
99
+ compiled_hash << "\"#{key.to_s}\": #{type_cast(value)}"
100
+ end
101
+
102
+ '{' + compiled_hash.join(', ') + '}'
103
+ end
94
104
 
95
105
  def start_indent
96
106
  @indent += 1
@@ -1,3 +1,3 @@
1
1
  module JSONBuilder
2
- VERSION = '2.0.3'.freeze
2
+ VERSION = '2.0.4'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
+ $:.unshift(File.expand_path('../../lib', File.dirname(__FILE__)))
1
2
  require 'json_builder'
2
- j = JSONBuilder::Generator.new
3
+ j = JSONBuilder::Generator.new(:pretty => true)
3
4
 
4
5
  j.name "Garrett Bjerkhoel"
5
6
  j.birthday Time.local(1991, 9, 14)
@@ -10,9 +11,7 @@ j.street do
10
11
  j.state "New York"
11
12
  j.zip 10065
12
13
  end
13
- j.hashed {
14
- :my_name => "Garrett Bjerkhoel".split('')
15
- }
14
+ j.hashed({ :my_name => "Garrett Bjerkhoel".split('') })
16
15
  j.skills do
17
16
  j.ruby true
18
17
  j.asp false
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 3
10
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Garrett Bjerkhoel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-31 00:00:00 -07:00
18
+ date: 2010-09-10 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency