Class: Tinylinks::Formatter
- Inherits:
-
Object
- Object
- Tinylinks::Formatter
- Defined in:
- lib/tinylinks/formatter.rb
Instance Method Summary collapse
- #errors(data) ⇒ Object
-
#initialize(color: false) ⇒ Formatter
constructor
A new instance of Formatter.
- #link(data) ⇒ Object
- #link_list(data) ⇒ Object
- #tags(data) ⇒ Object
Constructor Details
Instance Method Details
#errors(data) ⇒ Object
33 34 35 36 37 |
# File 'lib/tinylinks/formatter.rb', line 33 def errors(data) data["errors"].flat_map do |field, | .map { |msg| @c.red("#{field} #{msg}") } end.join("\n") end |
#link(data) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/tinylinks/formatter.rb', line 9 def link(data) lines = [] lines << @c.bold("#{data["title"] || "(untitled)"} [##{data["id"]}]") lines << " #{@c.cyan(data["url"])}" lines << " #{@c.dim(data["description"])}" if data["description"] && !data["description"].empty? = (data) lines << " #{}" if lines.join("\n") end |
#link_list(data) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/tinylinks/formatter.rb', line 19 def link_list(data) return @c.dim("No results found") if data["links"].empty? lines = data["links"].map { |l| link(l) } lines << @c.dim(pagination(data["meta"])) if data["meta"] lines.join("\n\n") end |
#tags(data) ⇒ Object
27 28 29 30 31 |
# File 'lib/tinylinks/formatter.rb', line 27 def (data) return @c.dim("No results found") if data["tags"].empty? data["tags"].map { |t| "#{@c.green(t["name"])} #{@c.dim("(#{t["count"]})")}" }.join("\n") end |