Class: SlackProgressBar::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_progress_bar/generator.rb

Constant Summary collapse

Error =
Class.new(StandardError)
CommandFailedError =
Class.new(Error)
ImageMagickError =
Class.new(Error)
ImageMagickMissingError =
Class.new(ImageMagickError)
ImageMagickOutdatedError =
Class.new(ImageMagickError)
OutputError =
Class.new(Error)
OutputMissingError =
Class.new(OutputError)
OutputNotWritableError =
Class.new(OutputError)
DEFAULT_COLORS =

The order in which these colors are configured is important; they will appear in the same order in a rendered progress bar.

The default colors below were borrowed from GitHub’s Primer color system. See: primer.style

Each color consists of a six hex digits describing the RGB color and two additional hex digits to describe the color’s transparency. “00” is fully transparent and “ff” is fully opaque.

{
  "p" => "6f42c1ff", # purple
  "b" => "0366d6ff", # blue
  "g" => "28a745ff", # green
  "y" => "ffd33dff", # yellow
  "o" => "f66a0aff", # orange
  "r" => "d73a49ff", # red
  "w" => "959da544", # white
}.freeze
DEFAULT_OUTPUT =
"./"
IMAGE_MAGICK_VERSION_PATTERN =
/Version: ImageMagick (?<major_version>\d+)\.[^\s]+/
MINIMUM_IMAGE_MAGICK_MAJOR_VERSION =
6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors: DEFAULT_COLORS, prefix: config.prefix, output: DEFAULT_OUTPUT) ⇒ Generator

Returns a new instance of Generator.



45
46
47
48
49
# File 'lib/slack_progress_bar/generator.rb', line 45

def initialize(colors: DEFAULT_COLORS, prefix: config.prefix, output: DEFAULT_OUTPUT)
  @colors = colors
  @prefix = prefix
  @output = output
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



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

def colors
  @colors
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

Instance Method Details

#configObject



51
52
53
# File 'lib/slack_progress_bar/generator.rb', line 51

def config
  @config ||= SlackProgressBar.config
end

#generateObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/slack_progress_bar/generator.rb', line 55

def generate
  check_image_magick!
  check_output!

  generate_left_caps
  generate_right_caps
  generate_circles
  generate_stripes
  generate_qr_code
end