module JSON::Pure::Generator::GeneratorMethods::Hash

Private Instance Methods

json_transform(state) click to toggle source
# File lib/tungsten/common.rb, line 110
def json_transform(state)
  valid_keys = 0
    
  delim = ','
  delim << state.object_nl
  result = '{'
  result << state.object_nl
  depth = state.depth += 1
  first = true
  indent = !state.object_nl.empty?
  keys().sort{ |a, b| a.to_s() <=> b.to_s() }.each{|key|
    value = self[key]
    json = value.to_json(state)
    if json == ""
      next
    end
    valid_keys = valid_keys+1
      
    result << delim unless first
    result << state.indent * depth if indent
    result << key.to_s.to_json(state)
    result << state.space_before
    result << ':'
    result << state.space
    result << json
    first = false
  }
  depth = state.depth -= 1
  result << state.object_nl
  result << state.indent * depth if indent if indent
  result << '}'
    
  if valid_keys == 0 && depth != 0
    return ""
  end
    
  result
end