Class: Boppers::Notifier::Stdout

Inherits:
Object
  • Object
show all
Defined in:
lib/boppers/notifier/stdout.rb

Constant Summary collapse

COLORS =
{
  green: "\e[32m",
  red: "\e[31m"
}.freeze
NO_COLOR =
"\e[0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subscribe: nil) ⇒ Stdout

Returns a new instance of Stdout.



15
16
17
# File 'lib/boppers/notifier/stdout.rb', line 15

def initialize(subscribe: nil)
  @subscribe = subscribe
end

Instance Attribute Details

#subscribeObject (readonly)

Returns the value of attribute subscribe.



13
14
15
# File 'lib/boppers/notifier/stdout.rb', line 13

def subscribe
  @subscribe
end

Instance Method Details

#call(title, message, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/boppers/notifier/stdout.rb', line 19

def call(title, message, options)
  color = COLORS.fetch(options[:color], NO_COLOR)
  message = message
            .gsub(/^/m, "   ")
            .lines
            .map {|line| "#{color}#{line}#{NO_COLOR}" }
            .join

  puts [
    "#{color}## #{title}#{NO_COLOR}",
    message,
    "\n"
  ].join("\n")
end