class Andrewmcodes::Center

Attributes

columns[RW]
output[RW]

Public Class Methods

new(output:, columns:) click to toggle source
# File lib/andrewmcodes/center.rb, line 7
def initialize(output:, columns:)
  @output = output
  @columns = columns
end

Public Instance Methods

centered_content() click to toggle source
# File lib/andrewmcodes/center.rb, line 28
def centered_content
  spaces = centering_spaces
  "#{spaces}#{output}#{spaces}"
end
centering_spaces() click to toggle source
# File lib/andrewmcodes/center.rb, line 12
def centering_spaces
  if output.is_a? String
    spaces(output.strip.length.to_i)
  elsif output.is_a? Integer
    spaces(output)
  else
    p "ERROR"
  end
end
spaces(length) click to toggle source
# File lib/andrewmcodes/center.rb, line 22
def spaces(length)
  spaces_needed = ((columns - length) / 2) - 1
  spaces_string = Array.new(spaces_needed, " ").join("")
  spaces_string
end