Class: GithubCLI::Formatters::CSV
- Inherits:
-
Object
- Object
- GithubCLI::Formatters::CSV
- Defined in:
- lib/github_cli/formatters/csv.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(response) ⇒ CSV
constructor
A new instance of CSV.
- #render_headers(response) ⇒ Object
- #render_line(index, item) ⇒ Object
Constructor Details
#initialize(response) ⇒ CSV
Returns a new instance of CSV.
7 8 9 |
# File 'lib/github_cli/formatters/csv.rb', line 7 def initialize(response) @response = response end |
Instance Method Details
#format ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/github_cli/formatters/csv.rb', line 11 def format case @response when Array render_headers @response.first @response.each_with_index do |item, indx| render_line indx, item Terminal.newline end when Hash render_headers @response render_line 1, @response else Terminal.line "#{@response}\n" end end |
#render_headers(response) ⇒ Object
27 28 29 30 |
# File 'lib/github_cli/formatters/csv.rb', line 27 def render_headers(response) output = GithubCLI::Util.flatten_hash(response.to_hash) Terminal.line "Index,#{output.keys.join(',')}\n" end |
#render_line(index, item) ⇒ Object
32 33 34 35 |
# File 'lib/github_cli/formatters/csv.rb', line 32 def render_line(index, item) output = GithubCLI::Util.flatten_hash(item.to_hash) $stdout.printf "%d,%s", index, output.values.join(',') end |