Class: Njunusk::Center
- Inherits:
-
Object
- Object
- Njunusk::Center
- Defined in:
- lib/njunusk/center.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #centered_content ⇒ Object
- #centering_spaces ⇒ Object
-
#initialize(output:, columns:) ⇒ Center
constructor
A new instance of Center.
- #spaces(length) ⇒ Object
Constructor Details
#initialize(output:, columns:) ⇒ Center
Returns a new instance of Center.
7 8 9 10 |
# File 'lib/njunusk/center.rb', line 7 def initialize(output:, columns:) @output = output @columns = columns end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/njunusk/center.rb', line 5 def columns @columns end |
#output ⇒ Object
Returns the value of attribute output.
5 6 7 |
# File 'lib/njunusk/center.rb', line 5 def output @output end |
Instance Method Details
#centered_content ⇒ Object
28 29 30 31 |
# File 'lib/njunusk/center.rb', line 28 def centered_content spaces = centering_spaces "#{spaces}#{output}#{spaces}" end |
#centering_spaces ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/njunusk/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) ⇒ Object
22 23 24 25 26 |
# File 'lib/njunusk/center.rb', line 22 def spaces(length) spaces_needed = ((columns - length) / 2) - 1 spaces_string = Array.new(spaces_needed, " ").join("") spaces_string end |