Class: Ppjson::StreamJsonWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ppjson/stream_json_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = $stdout) ⇒ StreamJsonWriter

Returns a new instance of StreamJsonWriter.



5
6
7
# File 'lib/ppjson/stream_json_writer.rb', line 5

def initialize(stream = $stdout)
  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



3
4
5
# File 'lib/ppjson/stream_json_writer.rb', line 3

def stream
  @stream
end

Instance Method Details

#write(json, options = {:pretty => true}) ⇒ Object



9
10
11
12
# File 'lib/ppjson/stream_json_writer.rb', line 9

def write(json, options = {:pretty => true})
  hash = from_json(json)
  stream.puts MultiJson.dump(hash, options)
end