Skip to content

Instantly share code, notes, and snippets.

@lithtle
Created June 7, 2012 03:23
Show Gist options
  • Save lithtle/2886345 to your computer and use it in GitHub Desktop.
Save lithtle/2886345 to your computer and use it in GitHub Desktop.
グキッ
#! /usr/bin/ruby -Ku
# -*- coding:utf-8 -*-
# 突然の死(AA略 を表示して遊ぶ
#
# Date:: 2012-06-07
# Author:: lithtle
# Copyright:: copyright (c) 2012 lithtle
# Example::
# _人人人人_
#
# > 突然の死 <
#
#  ̄ Y^Y^Y ̄
# ヘルプメッセージを表示
def help
puts <<-EOF
this is ruby script decolating string like
_人人人人_
> 突然の死 <
 ̄ Y^Y^Y ̄
------------------------------
usage: ruby #{$0} [option] string
option:
-h: display help only
EOF
end
# 文字列を整形して表示
# === Args
# _str_ : 表示する文字列
# === Note
# 大体あってればいいんだよ!!!!!
def totsuzen_no_shi(str)
unless str =~ /^[ -~。-゚]*$/ # 半角を含む
# 日本語(utf-8入力)の長さを得る
len = str.split(//u).length
zenkaku = true
else
len = str.length
zenkaku = false
end
puts "_" + "人" * (!zenkaku ? (len * 0.5 + 0.1).ceil : len + 1) + "_"
puts "> " + str + " <"
puts " ̄" + "^Y" * (!zenkaku ? (len * 0.39) : len * 0.75)+ "^ ̄"
end
# メイン関数
def main
argv = ARGV
argc = ARGV.length
# カスみたいなオプション処理
if (str = argv.shift) == "-h"
help
exit
else
# カスみたいなエラーメッセージ, 役に立ってるか不明
if argv.length > 1
puts "error:invalid argument"
exit
end
totsuzen_no_shi(str)
end
end
if $0 == __FILE__
main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment