Class: GithubCLI::Formatter
- Inherits:
-
Object
- Object
- GithubCLI::Formatter
- Defined in:
- lib/github_cli/formatter.rb
Overview
This is the main entry point for formatting output. It delegates to other objects like Formatter::Table to perform actual rendering.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #determine_output_formatter ⇒ Object
-
#initialize(response, options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
- #render_output ⇒ Object
-
#render_status ⇒ Object
Render status code.
Constructor Details
#initialize(response, options = {}) ⇒ Formatter
Returns a new instance of Formatter.
10 11 12 13 |
# File 'lib/github_cli/formatter.rb', line 10 def initialize(response, ={}) @response = response @format = [:format] end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/github_cli/formatter.rb', line 8 def format @format end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/github_cli/formatter.rb', line 8 def response @response end |
Instance Method Details
#determine_output_formatter ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/github_cli/formatter.rb', line 21 def determine_output_formatter case format.to_s when 'table', /table:v.*/, /table:h.*/ formatter = Formatters::Table.new(response, :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_output ⇒ Object
15 16 17 18 19 |
# File 'lib/github_cli/formatter.rb', line 15 def render_output render_status Terminal.paged_output determine_output_formatter end |
#render_status ⇒ Object
Render status code
39 40 41 42 43 44 |
# File 'lib/github_cli/formatter.rb', line 39 def render_status if response.respond_to? :status Terminal.line "Response Status: #{response.status}\n" Terminal.newline end end |