Module: Format
- Defined in:
- lib/format.rb
Class Method Summary collapse
- .format_quote(quote) ⇒ Object
- .padding(str, spaces = 1) ⇒ Object
- .space(str, spaces = 1) ⇒ Object
- .to_80(str) ⇒ Object
- .to_array(quote) ⇒ Object
Class Method Details
.format_quote(quote) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/format.rb', line 30 def self.format_quote(quote) = self.padding(quote, 2) # => Add padding to the quote. space = ' ' * 80 # => Filler to highlight. [ Qotd.color, space, , space, Qotd.clear, ] end |
.padding(str, spaces = 1) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/format.rb', line 43 def self.padding(str, spaces = 1) qarray = self.to_array(str) if qarray.length > 1 pstr = "" last = qarray.length - 1 (0...last).each do |line| text = self.space(qarray[line], spaces) filler = self.to_80(text) pstr << text << filler << "\n" end text = self.space(qarray[last], spaces) pstr << text << self.to_80(text) return pstr else text = self.space(str, spaces) return text << self.to_80(text) end end |
.space(str, spaces = 1) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/format.rb', line 5 def self.space(str, spaces = 1) padding = ' ' * spaces return "%s%s%s" % [ padding, str, padding ] end |
.to_80(str) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/format.rb', line 15 def self.to_80(str) chars = 80 - str.length # => length left to 80th char in line. padding = "" (1..chars).each do |i| padding << ' ' end return padding end |
.to_array(quote) ⇒ Object
26 27 28 |
# File 'lib/format.rb', line 26 def self.to_array(quote) quote.split(/\n/) end |