Class: RDBr::Web::JsonPageStream

Inherits:
Object
  • Object
show all
Defined in:
lib/rdbr/web/json_page_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ JsonPageStream

Returns a new instance of JsonPageStream.



4
5
6
# File 'lib/rdbr/web/json_page_stream.rb', line 4

def initialize(page)
  @attributes = page.to_h
end

Instance Method Details

#each(&writer) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rdbr/web/json_page_stream.rb', line 8

def each(&writer)
  writer.call('{')
  @attributes.each_with_index do |(key, value), index|
    writer.call(',') unless index.zero?
    writer.call("#{JSON.generate(key)}:")
    key == :rows ? yield_rows(value, &writer) : writer.call(JSON.generate(value))
  end
  writer.call('}')
end