Class: Slk::Formatters::MarkdownOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/formatters/markdown_output.rb

Overview

Markdown output adapter with same interface as Output Produces markdown formatting instead of ANSI colors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout, err: $stderr, color: nil, verbose: false, quiet: false) ⇒ MarkdownOutput

Accept color: parameter for interface compatibility with Output (ignored for markdown)



11
12
13
14
15
16
# File 'lib/slk/formatters/markdown_output.rb', line 11

def initialize(io: $stdout, err: $stderr, color: nil, verbose: false, quiet: false) # rubocop:disable Lint/UnusedMethodArgument
  @io = io
  @err = err
  @verbose = verbose
  @quiet = quiet
end

Instance Attribute Details

#quietObject (readonly)

Returns the value of attribute quiet.



8
9
10
# File 'lib/slk/formatters/markdown_output.rb', line 8

def quiet
  @quiet
end

#verboseObject (readonly)

Returns the value of attribute verbose.



8
9
10
# File 'lib/slk/formatters/markdown_output.rb', line 8

def verbose
  @verbose
end

Instance Method Details

#blue(text) ⇒ Object

blue -> ‘text` (code for timestamps)



70
71
72
# File 'lib/slk/formatters/markdown_output.rb', line 70

def blue(text)
  "`#{text}`"
end

#bold(text) ⇒ Object

Markdown formatting helpers - string interpolation handles nil conversion bold -> text



50
51
52
# File 'lib/slk/formatters/markdown_output.rb', line 50

def bold(text)
  "**#{text}**"
end

#cyan(text) ⇒ Object

cyan -> ‘text` (code for metadata like timestamps)



80
81
82
# File 'lib/slk/formatters/markdown_output.rb', line 80

def cyan(text)
  "`#{text}`"
end

#debug(message) ⇒ Object



42
43
44
45
46
# File 'lib/slk/formatters/markdown_output.rb', line 42

def debug(message)
  return unless @verbose

  @err.puts("*[debug]* #{message}")
end

#error(message) ⇒ Object



26
27
28
# File 'lib/slk/formatters/markdown_output.rb', line 26

def error(message)
  @err.puts("**Error:** #{message}")
end

#gray(text) ⇒ Object

gray -> text (italics for secondary info)



85
86
87
# File 'lib/slk/formatters/markdown_output.rb', line 85

def gray(text)
  "*#{text}*"
end

#green(text) ⇒ Object

green -> plain text (success doesn’t need markup)



60
61
62
# File 'lib/slk/formatters/markdown_output.rb', line 60

def green(text)
  text.to_s
end

#info(message) ⇒ Object



38
39
40
# File 'lib/slk/formatters/markdown_output.rb', line 38

def info(message)
  puts(message)
end

#magenta(text) ⇒ Object

magenta -> text (italics for secondary)



75
76
77
# File 'lib/slk/formatters/markdown_output.rb', line 75

def magenta(text)
  "*#{text}*"
end


22
23
24
# File 'lib/slk/formatters/markdown_output.rb', line 22

def print(message)
  @io.print(message) unless @quiet
end

#puts(message = '') ⇒ Object



18
19
20
# File 'lib/slk/formatters/markdown_output.rb', line 18

def puts(message = '')
  @io.puts(message) unless @quiet
end

#red(text) ⇒ Object

red -> text (emphasis for errors)



55
56
57
# File 'lib/slk/formatters/markdown_output.rb', line 55

def red(text)
  "**#{text}**"
end

#success(message) ⇒ Object



34
35
36
# File 'lib/slk/formatters/markdown_output.rb', line 34

def success(message)
  puts("#{message}")
end

#warn(message) ⇒ Object



30
31
32
# File 'lib/slk/formatters/markdown_output.rb', line 30

def warn(message)
  @err.puts("*Warning:* #{message}") unless @quiet
end

#with_quiet(value) ⇒ Object



93
94
95
# File 'lib/slk/formatters/markdown_output.rb', line 93

def with_quiet(value)
  self.class.new(io: @io, err: @err, verbose: @verbose, quiet: value)
end

#with_verbose(value) ⇒ Object



89
90
91
# File 'lib/slk/formatters/markdown_output.rb', line 89

def with_verbose(value)
  self.class.new(io: @io, err: @err, verbose: value, quiet: @quiet)
end

#yellow(text) ⇒ Object

yellow -> text (italics for warnings)



65
66
67
# File 'lib/slk/formatters/markdown_output.rb', line 65

def yellow(text)
  "*#{text}*"
end