Module: CommentBoxStringExtensions
- Defined in:
- lib/commentbox.rb
Instance Method Summary collapse
- #align_to(side, length) ⇒ Object
- #center_align(length) ⇒ Object
- #justify_to(length) ⇒ Object
- #right_justify_to(length) ⇒ Object
Instance Method Details
#align_to(side, length) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/commentbox.rb', line 70 def align_to (side, length) if side == :left self.justify_to length elsif side == :right self.right_justify_to length elsif side == :center self.center_align length else raise 'String#align_to : expected :left, :right, or :center here' end end |
#center_align(length) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/commentbox.rb', line 63 def center_align (length) if !length.is_even? then raise 'String#center_align : length must be even' end llength = ((length - self.length) / 2) rlength = llength if !self.length.is_even? then rlength += 1 end (' ' * llength) + self + (' ' * rlength) end |
#justify_to(length) ⇒ Object
57 58 59 |
# File 'lib/commentbox.rb', line 57 def justify_to (length) self << ' ' * (length - self.length) end |
#right_justify_to(length) ⇒ Object
60 61 62 |
# File 'lib/commentbox.rb', line 60 def right_justify_to (length) (' ' * (length - self.length)) + self end |