Class: JsonToTableDisplayer

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

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ JsonToTableDisplayer

Returns a new instance of JsonToTableDisplayer.



5
6
7
8
# File 'lib/json_to_table_displayer.rb', line 5

def initialize(json)
  @object = JSON.parse(json)
  @table = JsonToTable::Table.new(@object)
end

Instance Method Details



20
21
22
23
24
25
26
27
28
29
# File 'lib/json_to_table_displayer.rb', line 20

def print_terminal_child_tables
  @table.child_hashes.each do |child_hash|
    key = child_hash.keys.first
    puts "\n#{key}"

    child_table = JsonToTable::Table.new(child_hash[key])
    puts child_table.terminal_table
    @table.child_hashes.concat child_table.child_hashes
  end
end


16
17
18
# File 'lib/json_to_table_displayer.rb', line 16

def print_terminal_table
  puts @table.terminal_table
end

#runObject



10
11
12
13
14
# File 'lib/json_to_table_displayer.rb', line 10

def run
  print_terminal_table

  print_terminal_child_tables
end