Module: SuddenDeath

Defined in:
lib/sudden_death/version.rb,
lib/sudden_death/sudden_death.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.sudden_death(text) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sudden_death/sudden_death.rb', line 4

def self.sudden_death(text)
  lines = text.each_line.to_a.collect{|line| line.chomp }
  max_width = lines.collect{|line| text_width(line)}.max

  top = "" * (max_width / 2)
  middle = lines.collect{|line|
    "> #{line + (" " * (max_width - text_width(line)))} <"
  }.join("\n")
  bottom = "" * (max_width / 2)

  <<"SUDDENDEATH"
_人#{top   }人_
#{middle}
 ̄Y#{bottom}Y ̄
SUDDENDEATH
end

.text_width(line) ⇒ Object



21
22
23
24
# File 'lib/sudden_death/sudden_death.rb', line 21

def self.text_width(line)
  hankaku_count = line.split(//).count {|c| c.ascii_only? }
  hankaku_count + (line.size - hankaku_count) * 2
end