Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/a1447ll_hpbd/message.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(name) ⇒ Message
constructor
A new instance of Message.
- #insert(txt, str) ⇒ Object
Constructor Details
#initialize(name) ⇒ Message
Returns a new instance of Message.
2 3 4 5 6 |
# File 'lib/a1447ll_hpbd/message.rb', line 2 def initialize name @width = name.length < 31 ? 33 : name.length + 9 - name.length%4 @height = 11 @name = name end |
Instance Method Details
#draw ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/a1447ll_hpbd/message.rb', line 14 def draw msg = %w() msg[0] = msg[@height-1] = "x . " * (@width/4) + "x" for i in 1 .. @height-2 do msg[i] = i%2 == 1 ? ("." + " " * (@width - 2) + ".") : ("x" + " " * (@width - 2) + "x") end time = "[ " + Time.now.strftime("%Y/%m/%d") + " ]" insert ">>> HAPPY BIRTHDAY! <<<", msg[2] insert time, msg[4] insert @name, msg[6] insert "\\(*^ 3 ^*)/", msg[8] for i in 0 .. msg.size-1 puts msg[i] end end |
#insert(txt, str) ⇒ Object
8 9 10 11 12 |
# File 'lib/a1447ll_hpbd/message.rb', line 8 def insert txt, str beg = (@width - txt.length)/2 fin = beg + txt.length - 1 str[beg..fin] = txt end |