Module: Accio::Formatter

Defined in:
lib/accio/formatter.rb

Overview

Public: Formats the snippet output for the terminal.

Constant Summary collapse

COLOR =
Term::ANSIColor

Class Method Summary collapse

Class Method Details

Public: Colorizes a code snippet.

Returns a colorized String.



27
28
29
# File 'lib/accio/formatter.rb', line 27

def print_code(snippet)
  COLOR.send(:green, snippet)
end

Public: Colorizes a code comment.

Returns a colorized String.



34
35
36
# File 'lib/accio/formatter.rb', line 34

def print_comment(comment)
  COLOR.send(:yellow, comment)
end

Public: Colorizes the title of a group.

Returns a colorized String.



13
14
15
# File 'lib/accio/formatter.rb', line 13

def print_group_title(title)
  COLOR.send(:red, title)
end

Public: Colorizes the title of a snippet.

Returns a colorized String.



20
21
22
# File 'lib/accio/formatter.rb', line 20

def print_snippet_title(title)
  COLOR.send(:blue, title)
end

.template(group_title, snippet_title, comment, code) ⇒ Object

Public: Prints a table with group title, snippet title, comment and code.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/accio/formatter.rb', line 40

def template(group_title, snippet_title, comment, code)
  rows = []
  rows << [print_group_title(group_title)]
  rows << :separator
  rows << [print_snippet_title(snippet_title)]
  unless comment.text.length == 0
    rows << :separator
    rows << [print_comment(comment.text)]
  end

  puts Terminal::Table.new(rows: rows)
  puts print_code(code.text)
end