Sha256: 8dd88be2f60f8b986ad0101f2111f358b41280df30340736f8129d41300ec477

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

module GithubCLI
  # This is the main entry point for formatting output.
  # It delegates to other objects like Formatter::Table
  # to perform actual rendering.
  class Formatter
    attr_reader :response, :format

    def initialize(response, options={})
      @response = response
      @format   = options[:format]
    end

    def render_output
      render_status
      Terminal.paged_output
      determine_output_formatter
    end

    def determine_output_formatter
      case format.to_s
      when 'table', /table:v.*/, /table:h.*/
        formatter = Formatters::Table.new(response.body,
                      :transform => format.to_s.split(':').last)
        formatter.format
      when 'csv'
        formatter = Formatters::CSV.new(response)
        formatter.format
      when 'json'
        'json output'
      else
        raise UnknownFormatError, format
      end
    end

    # Render status code
    def render_status
      if response.respond_to? :status
        Terminal.line "Response Status: #{response.status}\n"
        Terminal.newline
      end
    end

  end # Formatter
end # GithubCLi

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
github_cli-0.5.6 lib/github_cli/formatter.rb
github_cli-0.5.5 lib/github_cli/formatter.rb
github_cli-0.5.4 lib/github_cli/formatter.rb