Module: SeedFormatter

Defined in:
lib/seed_formatter.rb,
lib/seed_formatter/version.rb

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Instance Method Details

#error(message, options = {}) ⇒ Object

A preset formatter with overridable options



37
38
39
40
41
# File 'lib/seed_formatter.rb', line 37

def error(message, options = {})
  options[:prefix] ||= "  - "
  options[:color] ||= :red
  output message, options
end

#message(message, options = {}) ⇒ Object

A preset formatter with overridable options



23
24
25
26
27
# File 'lib/seed_formatter.rb', line 23

def message(message, options = {})
  options[:prefix] ||= "*** "
  options[:color] ||= :white
  output message, options
end

#output(message, options = {}) ⇒ Object

Outputs a message with a set of given options

Examples:

Print out an error message

SeedFormatter.output "Some error", {:prefix => "!!! ", :color => :red}
# outputs "!!! Some error" in red text

Parameters:

  • message: (String)

    The message to format

  • options: (Hash)

    A hash of options to apply to the string

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • prefix: (String)

    A prefix for the message. EG: “–> message”

  • color: (String)

    A Symbol representing the color from the Colored gem. See: Colored.colors

  • suffix: (String)

    A String suffix for the message. EG: “message !!!”



17
18
19
20
# File 'lib/seed_formatter.rb', line 17

def output(message, options = {})
  options[:color] ||= :white
  $stdout.puts "#{options[:prefix]}#{message}#{options[:suffix]}".send(options[:color])
end

#spacerObject



43
44
45
# File 'lib/seed_formatter.rb', line 43

def spacer
  $stdout.puts ""
end

#success(message, options = {}) ⇒ Object

A preset formatter with overridable options



30
31
32
33
34
# File 'lib/seed_formatter.rb', line 30

def success(message, options = {})
  options[:prefix] ||= "  + "
  options[:color] ||= :green
  output message, options
end