sudden_death 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  _人人人人人人_
4
4
  > 突然の死 <
5
-  ̄^Y^Y^Y^Y^ ̄
5
+  ̄YYYYYY ̄
6
6
 
7
7
  ## Installation
8
8
 
@@ -24,7 +24,15 @@ Or install it yourself as:
24
24
 
25
25
  _人人人人人人_
26
26
  > 突然の死 <
27
-  ̄^Y^Y^Y^Y^ ̄
27
+  ̄YYYYYY ̄
28
+
29
+ "突然の死突然の死\n突然の死\n突然の死突然の死突然の死".sudden_death # =>
30
+
31
+ _人人人人人人人人人人人人人人_
32
+ > 突然の死突然の死  <
33
+ > 突然の死  <
34
+ > 突然の死突然の死突然の死 <
35
+  ̄YYYYYYYYYYYYYY ̄
28
36
 
29
37
  ## Contributing
30
38
 
@@ -2,15 +2,24 @@
2
2
 
3
3
  module SuddenDeath
4
4
  def self.sudden_death(text)
5
- hankaku_count = text.split(//).count {|c| c.ascii_only? }
6
- text_width = hankaku_count + (text.size - hankaku_count) * 2
7
- top = "人" * (text_width / 2)
8
- bottom = "Y^" * (text_width / 2)
5
+ lines = text.each_line.to_a.collect{|line| line.chomp }
6
+ max_width = lines.collect{|line| text_width(line)}.max
7
+
8
+ top = "" * (max_width / 2)
9
+ middle = lines.collect{|line|
10
+ "> #{line + (" " * (max_width - text_width(line)))} <"
11
+ }.join("\n")
12
+ bottom = "Y" * (max_width / 2)
9
13
 
10
14
  <<"SUDDENDEATH"
11
- _人#{top}人_
12
- > #{text} <
13
-  ̄^#{bottom}
15
+ _人#{top }人_
16
+ #{middle}
17
+  ̄Y#{bottom}Y ̄
14
18
  SUDDENDEATH
15
19
  end
20
+
21
+ def self.text_width(line)
22
+ hankaku_count = line.split(//).count {|c| c.ascii_only? }
23
+ hankaku_count + (line.size - hankaku_count) * 2
24
+ end
16
25
  end
@@ -1,3 +1,3 @@
1
1
  module SuddenDeath
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -6,7 +6,17 @@ describe "sudden_death" do
6
6
  "突然の死".sudden_death.should == <<STR
7
7
  _人人人人人人_
8
8
  > 突然の死 <
9
-  ̄^Y^Y^Y^Y^ ̄
9
+  ̄YYYYYY ̄
10
+ STR
11
+ end
12
+
13
+ it "改行を含む文字列の場合、フキダシが複数行に渡る" do
14
+ "突然の死突然の死\n突然の死\n突然の死突然の死突然の死".sudden_death.should == <<STR
15
+ _人人人人人人人人人人人人人人_
16
+ > 突然の死突然の死  <
17
+ > 突然の死  <
18
+ > 突然の死突然の死突然の死 <
19
+  ̄YYYYYYYYYYYYYY ̄
10
20
  STR
11
21
  end
12
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sudden_death
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: