Class: FootballCli::Format::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/football_cli/format/json.rb

Instance Attribute Summary

Attributes inherited from Base

#columns, #response, #rows, #title

Instance Method Summary collapse

Methods inherited from Base

#goal_columns, #initialize, #output, #qualification

Constructor Details

This class inherits a constructor from FootballCli::Format::Base

Instance Method Details

#generateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/football_cli/format/json.rb', line 7

def generate
  response.each do |data|
    rows.push(
      Hash[columns.collect {|c|
        if goal_columns.include?(c)
          [c, data[:result][c]]
        else
          [c, data[c]]
        end
      }]
    )
  end

  @generate ||= JSON.pretty_generate(rows)
end