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.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#quiet ⇒ Object
readonly
Returns the value of attribute quiet.
-
#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_message ⇒ Object
- #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 14 15 |
# File 'lib/github_cli/formatter.rb', line 10 def initialize(response, ={}) @response = response = [:message] @format = [:format] @quiet = [:quiet] 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 |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/github_cli/formatter.rb', line 8 def end |
#quiet ⇒ Object (readonly)
Returns the value of attribute quiet.
8 9 10 |
# File 'lib/github_cli/formatter.rb', line 8 def quiet @quiet 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/github_cli/formatter.rb', line 25 def determine_output_formatter case format.to_s when 'table', /table:v.*/, /table:h.*/ if response.body && !response.body.empty? formatter = Formatters::Table.new(response.body, :transform => format.to_s.split(':').last) formatter.format end when 'csv' formatter = Formatters::CSV.new(response) formatter.format when 'json' 'json output' else raise UnknownFormatError, format end end |
#render_message ⇒ Object
51 52 53 54 55 |
# File 'lib/github_cli/formatter.rb', line 51 def if Terminal.line end end |
#render_output ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/github_cli/formatter.rb', line 17 def render_output render_status return if quiet Terminal.paged_output determine_output_formatter end |
#render_status ⇒ Object
Render status code
44 45 46 47 48 49 |
# File 'lib/github_cli/formatter.rb', line 44 def render_status if response.respond_to? :status Terminal.line "Response Status: #{response.status}\n" Terminal.newline end end |