Class: Glsnip::Formatter
- Inherits:
-
Object
- Object
- Glsnip::Formatter
- Defined in:
- lib/glsnip/formatter.rb
Overview
Formatter
- Author
-
Richard Davis
- Copyright
-
Copyright 2019 Richard Davis
- License
-
GNU Public License 3
Formats execution results and prints to the terminal
Class Method Summary collapse
Class Method Details
.create_success(json) ⇒ Object
46 47 48 49 |
# File 'lib/glsnip/formatter.rb', line 46 def self.create_success(json) body = JSON.parse(json) "Snippet \"#{body['title']}\" (#{body['file_name']} | #{body['id']}) successfully created: #{body['web_url']}".colorize(:green) end |
.error(json) ⇒ Object
32 33 34 35 |
# File 'lib/glsnip/formatter.rb', line 32 def self.error(json) body = JSON.parse(json) "Failure: #{body['message']}".colorize(:red) end |
.list(json) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/glsnip/formatter.rb', line 37 def self.list(json) body = JSON.parse(json) snippets = [] body.each do |snippet| snippets.push "\"#{snippet['title']}\" (#{snippet['file_name']} | #{snippet['id']}): #{snippet['web_url']}".colorize(:light_blue) end snippets end |